How about n is negative?


  • 0
    C

    Dear all,
    In this problem, how can I deal with the case n < 0?

    class Solution {
    public:
        int singleNumber(int A[], int n) {
            if( n == 0 )
                return 0;
            int temp = A[0];
            for( int i = 1; i < n; ++i ) {
                temp ^= A[i]; 
            }
            return temp;
        }
    };
    

    Thanks,
    Chunting


  • 0

    No, n cannot be < 0.


Log in to reply
 

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