Java clean solution


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

Log in to reply
 

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