My Java Solution, easy to understand


  • 1
    public class Solution {
        public int removeDuplicates(int[] nums) {
            int index = 1;
            
            for(int i = 1; i < nums.length; i++)
               if(nums[i] > nums[i - 1])
                    nums[index++] = nums[i];
            return index;
        }
    }
    

Log in to reply
 

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