clean C++ solution


  • 0
    J
    class Solution {
    public:
        int removeDuplicates(vector<int>& nums) {
            int len = nums.size();
            if(len <= 2) return len;
            int newLen = 0;
            bool flag = false;
            for(int j = 1; j < len; j++){
                if(nums[newLen] == nums[j]){
                    if(!flag){
                        flag = true;
                        nums[++newLen] = nums[j];
                    }
                }
                else{
                    nums[++newLen] = nums[j];
                    flag = false;
                }
            }
            return newLen + 1;
        }
    };
    

Log in to reply
 

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