Given an array of integers, every element appears twice except for one. Find that single one.Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
线性时间完成,不花费多余空间,问题特殊,异或运算就解决了。
public class Solution { public int singleNumber(int[] nums) { int result = 0; for(int num: nums) { result^=num; } return result; } }