You are viewing a single comment's thread. Return to all comments →
Wrote this solution by Swift, not perfect about alghoritms anyone can improve this for any suggest?
func lonelyInteger(arr : [Int]) -> Int{ var checkinNum = -1 var count = 0 var res = 0 var sorted = arr.sorted(by: <) var uniqArr = Array(Set(sorted)) uniqArr.forEach { num in checkinNum = num count = 0 sorted.filter { filterNum in if checkinNum == filterNum { count += 1 return true } else{ return false } } if count == 2{ checkinNum = num } else{ res = num } } return res }
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 →
Wrote this solution by Swift, not perfect about alghoritms anyone can improve this for any suggest?