Share my C++ code with std iterator.

  • 0

    Since use std::unique is kind of cheater. Here is my code of C++ by means of std iterator.

    class Solution {
        int removeDuplicates(vector<int>& nums) {
            if(nums.size()<=1) return nums.size();
            auto targetPos = nums.begin();
            auto currentPos = nums.begin()+1;
                if(*currentPos == *targetPos){
                    *targetPos = *currentPos;
            return targetPos-nums.begin()+1;

Log in to reply

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