```
class Solution {
public:
int missingNumber(vector<int>& nums) {
int sum = 0;
for(int i = 0; i < nums.size(); ++i){
sum += nums[i];
}
if(nums.size() % 2 == 1)
return (nums.size() + 1) / 2 * nums.size() - sum;
else
return nums.size() / 2 * (nums.size() + 1) - sum;
}
};
```

Actually, the function can get the correct answer even sum overflow since we only care the gap between 1+2+...+n and the sum of number in nums.