knakul853

Untitled

Jul 17th, 2020
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. /**
  2. knakul853
  3. **/
  4.  
  5. class Solution {
  6. public:
  7.     int removeDuplicates(vector<int>& nums) {
  8.        
  9.         if(nums.empty()) return 0;
  10.         int n = (int)nums.size();
  11.        
  12.         int l = 0;
  13.        
  14.         for( int i = 1; i < n; i++ )
  15.         {
  16.             if(nums[l] !=  nums[i])
  17.             {
  18.                 nums[++l] = nums[i];
  19.             }
  20.         }
  21.        
  22.         return l+1;
  23.     }
  24. };
Add Comment
Please, Sign In to add comment