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