[LintCode] Single Number
1 2 3 4 5 6 7 8 9 10 11 12 |
public int singleNumber(int[] A) { if (A.length == 0) { return 0; } int n = A[0]; for(int i = 1; i < A.length; i++) { n = n ^ A[i]; } return n; } |
1 2 3 4 5 6 7 8 9 10 11 12 |
public int singleNumber(int[] A) { if (A.length == 0) { return 0; } int n = A[0]; for(int i = 1; i < A.length; i++) { n = n ^ A[i]; } return n; } |
Leave A Comment