Swift算法8-Single Number

Given an array of integers, every element appears twice except for one. Find that single one.

Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?

class Solution {
    func singleNumber(var nums: [Int]) -> Int {
        //if nums.count == 1 { return nums[0] }
        for i in 1..

well why i didn't check num.count == 1, it says an array of integerS. "S".
So i don't think it's necessary for me to check it.

and for ^: a ^ b = b ^ a, a ^ a = 0, a ^ 0 = a.

你可能感兴趣的:(Swift算法8-Single Number)