Simple Java, 8 lines. Beats 93.19 %


  • 0
    C
    public int removeDuplicates(int[] nums) {
    		if (nums == null || nums.length == 0) return 0;
    		int start = 0, current = 0;
    		int element = nums[start];
    		while (current < nums.length - 1) { 
    			if (nums[++current] > element) {
    				element = nums[current];
    				nums[++start] = element;
    			}
    		}
    		return start + 1;
    	}
    

Log in to reply
 

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