My AC c++ answer


  • 0
    K
           class Solution {
               public:
                    int removeDuplicates(vector<int>& nums) {
                          if(nums.empty()) return 0;
                          int pos = 0;
                          for(int i = 1; i<nums.size(); ++i) {
                                  if(nums[i] != nums[pos])
                                       nums[++pos] = nums[i];
                                  else
                                       continue;
                          }
                          return pos+1;
                    }
                };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.