sak1b

https://leetcode.com/problems/missing-number/

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