12ms C solution, no multiplication or bit manipulation


  • 0
    G
    int missingNumber(int* nums, int numsSize) {
        if (!nums || numsSize <= 0) return -1;
        int i, x = 0;
        for (i = 0; i < numsSize; i++) x += i + 1 - nums[i];
        return x;
    }

Log in to reply
 

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