Swift solution


  • 0
    class Solution {
        func singleNumber(_ nums: [Int]) -> [Int] {
            var diff = 0
            var result = [0, 0]
            
            for num in nums {
                diff ^= num
            }
            diff &= -diff
            for num in nums {
                if num & diff == 0 {
                    result[0] ^= num
                } else {
                    result[1] ^= num
                }
            }
            
            return result
        }
    }
    

Log in to reply
 

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