We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
funclonelyinteger(a:[Int])->Int{// Write your code herevardict:[Int:Int]=[:]// create Dictionary based on array that we havefornumberina{// check that number is in Dictionaryifdict.contains(where:{$0.key==number}){// add counter when already in itdict[number]!+=1}else{// initiate new numberdict[number]=1}}// get first dictionary where it has only one valueifletaloneNumber=dict.first(where:{$0.value==1}){returnaloneNumber.key}return0}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Lonely Integer
You are viewing a single comment's thread. Return to all comments →
here is my solution using dictionary with Swift