C++ , O(n)


  • 0
    B

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


Log in to reply
 

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