Why this code was accepted?


  • 0
    H
    class Solution {
    public:
        int singleNumber(int A[], int n) {
            sort(A,A+n);
            if(n==1) return A[0];
            for(int i=0;i<n;i++){
                if(A[i]!=A[++i]) return A[--i];
            }
        }
    };
    

    above is my code for single number, actually I am confused about why it was accepted. The complexity of Sort is O(N) ?


  • 0
    S

    sort is O(N log N). OJ is not strict enough, especially for NlogN and N.


Log in to reply
 

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