Shortest XOR solution in Swift


  • 0
    A
    class Solution {
        func singleNumber(_ nums: [Int]) -> Int {
            var single = 0
            for n in nums {
                single = single ^ n
            }
            return single
        }
    }
    

Log in to reply
 

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