136. Single Number
2018-04-07 本文已影响6人
衣介书生
题目分析
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?
思路参考
代码
public class Solution {
public int singleNumber(int[] A) {
int res = 0;
for(int a : A) {
res ^= a;
}
return res;
}
}