A C solution costs 12ms by insertion sort


  • 1
    O
    bool containsDuplicate(int* nums, int numsSize) {
        int *mov = nums+1;
        int *mov_end = nums + numsSize;
        int *mov_a,*mov_b;
        int tmp;
        
        while(mov<mov_end)
        {
            mov_a = mov;
            mov_b = mov - 1;
            while(mov_a>nums)
            {
                if(*mov_a>*mov_b)
                    break;
                else if(*mov_a==*mov_b)
                    return true;
                else
                {
                    tmp = *mov_a;
                    *mov_a = *mov_b;
                    *mov_b = tmp;
                    mov_a--;
                    mov_b--;
                }
            }
            mov++;
        }
        return false;
    }

Log in to reply
 

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