题目分析
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;
}
}
网友评论