JAVA-------------Easy Version To UnderStand!!!!!!!!!!!!!!!


  • 0
    H
    	public static int removeDuplicates(int[] nums) {
    	if (nums == null || nums.length == 0)
    		return 0;
    	if (nums.length == 1)
    		return 1;
    	int slow = 0, fast = 1, len = nums.length;
    	while (fast < len) {
    		if (nums[fast] != nums[slow]) {
    			nums[++slow] = nums[fast];
    		}
    		fast++;
    	}
    	return slow + 1;
    }

Log in to reply
 

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