题目
Given an array of integers, every element appears twice except for one. Find that single one.
解法一:
用无序图来存储数据,即m[2] = 1代表数字2在列表中出现了一次。时间复杂度o(n)
1 | class Solution { |
解法二
速度比较快的方法,用位运算可以大大提高运算速度。
xor(异或)的位运算,x ^ x = 0; 0 ^ y = y;
1 | class Solution { |