26 - Remove Duplicates from Sorted Array

解法一 - Two Pointer

class Solution {
public:
    int removeDuplicates(vector<int>& nums) {
        int size=0;
        if(nums.empty()) return size;

        for(int i=0; i<nums.size(); i++) {
            if(nums[size] != nums[i]) 
                nums[++size] = nums[i];
        }

        return size+1;
    }
};

results matching ""

    No results matching ""