SUPER-SHORT C++ sulotion


  • 0
    N
    class Solution {
    public:
        int removeDuplicates(vector<int>& nums) {
            int i=0,d=0,sz=nums.size();
            while(++i<sz) if(nums[i]!=nums[i-1]) nums[++d]=nums[i];
            return sz==0 ? 0 : d+1;
        }
    };

Log in to reply
 

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