Advertisement
Josif_tepe

Untitled

Dec 30th, 2022
869
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.30 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int missingNumber(vector<int>& nums) {
  4.         int n = nums.size();
  5.         int sum_of_array = 0;
  6.         for(int i = 0; i < n; i++) {
  7.             sum_of_array += nums[i];
  8.         }
  9.         int sum = n * (n + 1) / 2;
  10.         return sum - sum_of_array;
  11.        
  12.  
  13.     }
  14. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement