Using c++,32 ms , 15 lines,very very easy to understand


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

    I am a Chinese ,and I want to make friends with you, then we can talk about problems.
    And I want to improve my English.

    My email : skyqsk@126.com


Log in to reply
 

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