🎉 One-stop destination for all your technical interview Preparation 🎉
Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array.
class Solution{
public:
int missingNumber(vector<int> &nums){
int sum = 0, n = nums.size();
for (int i = 0; i < n; i++){
sum += nums[i];
}
return (n * (n + 1) / 2) - sum;
}
};