Swift solution


  • 0
    class Solution {
        func singleNumber(_ nums: [Int]) -> Int {
            var ones = 0
            var twos = 0
            
            for num in nums {
                ones = (ones ^ num) & ~twos
                twos = (twos ^ num) & ~ones
            }
            
            return ones
        }
    }
    

Log in to reply
 

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