leetcode Missing Number

Use the sumup of all the number subtract the sum of them.

1
2
3
4
5
int missingNumber(int* nums, int numsSize) {
long long int sum = 0;
for(int i = 0;i < numsSize;++ i) sum += nums[i];
return (numsSize + 1) * numsSize / 2 - sum;
}

,