Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int missingNumber(vector<int>& nums) {
- int n = nums.size();
- int sum_of_array = 0;
- for(int i = 0; i < n; i++) {
- sum_of_array += nums[i];
- }
- int sum = n * (n + 1) / 2;
- return sum - sum_of_array;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement