26. 删除排序数组中的重复项

26. 删除排序数组中的重复项–leetcode

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

你可能感兴趣的:(leetcode,leetcode)