136. Single Number
Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.
You must implement a solution with a linear runtime complexity and use only constant extra space.
位运算,对所有数值做二进制异或运算。
两个同样的值异或运算会等于0,最后和与单独的数字相等。
1 | class Solution { |
排序,然后遍历数组,如果第i个值不等于第i+1个则返回。
1 | class Solution { |
136. Single Number