Advertisement
Josif_tepe

Untitled

Dec 30th, 2022
873
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int missingNumber(vector<int>& nums) {
  4.         sort(nums.begin(), nums.end());
  5.         int n = nums.size();
  6.         for (int i = 0; i < n - 1; i++)
  7.         {
  8.             int razlika = nums[i + 1] - nums[i];
  9.             if(razlika == 2)
  10.             {
  11.                 return nums[i + 1] - 1;
  12.             }
  13.         }
  14.         if(nums[0] != 0) {
  15.             return 0;
  16.         }
  17.         else {
  18.             return nums[n - 1] + 1;
  19.         }
  20.        
  21.  
  22.     }
  23. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement