Concise solution


  • 0
    D
    public class Solution {
        public int removeDuplicates(int[] nums) {
            int slowIdx = 0;
            for (int i=1; i<nums.length; i++)
            {
                if(nums[slowIdx] != nums[i])
                {
                    slowIdx++;
                }    
                nums[slowIdx] = nums[i];
            }
            return nums.length == 0 ? 0 : slowIdx + 1;
        }
    }
    

Log in to reply
 

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