This is my code, used 22ms , I don't know how to improve it , could you give some advice?Thanks !


  • 2
    H
    int singleNumber(int A[], int n) {
        while(--n>0)A[0]^=A[n];
        return A[0];
    }

  • 0
    N

    Try to use an external variable instead of A[0]. My solution runs in 6ms when using an external variable


  • 0
    J

    Every loop you need to get a[0], if the array is too big, larger than the system pages for example, it will cause system interrupts.


Log in to reply
 

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