Easy C++ Solution


  • 0
    F
        int removeDuplicates(vector<int>& nums) {
            int slow = 0, fast = 1;
            while (fast < nums.size()) {
                if (nums[slow] == nums[fast]) ++fast;
                else nums[++slow] = nums[fast++];
            }
            return (nums.empty() ? 0 : slow + 1);
        }
    

Log in to reply
 

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