Swift Solution 16ms


  • 0
    M

    class Solution {
    func singleNumber(_ nums: [Int]) -> [Int] {

        var dupList : [Int: Int] = [:]
        var non  : [Int] = []
        
        for i in nums {
            
            if let index = dupList[i] {
                
                dupList.updateValue(dupList[i]! + 1, forKey: i)
                
            } else {
                dupList[i] = 1
            }
    
        }
        
        for (key, value) in dupList {
            if(value > 1){
                continue
            }
            non.append(key)
        }
        
        return non
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.