My C++ code (XOR)

  • 2
    class Solution {
        int singleNumber(int A[], int n) {
           int result = 0;
           int i;
           for(i=0; i<n; i++)
           { // XOR all the elements, the one appearing once will survive
               result ^=A[i];
           return result;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.