Golang solution with bitwise not operator


  • 0
    R
    func singleNumber(nums []int) int {
        ones := uint(0); twos := uint(0);
        for i := uint(0); i < uint(len(nums)); i++ {
            ones = (ones ^ uint(nums[i])) &^ twos
            twos = (twos ^ uint(nums[i])) &^ ones
        }
        return int(ones)
    }
    

Log in to reply
 

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