[LeetCode] 26. Remove Duplicates from Sorted Array java

3/8/2017来源:ASP.NET技巧人气:2009

/** 26. Remove Duplicates from Sorted Array * @param nums * @return 有序数组中删除重复数字 */ public int removeDuplicates(int[] nums) { int count = 0; int len = len = nums.length; for (int i=1; i<len; i++) { if (nums[i] == nums[i-1]) { count++; } else { nums[i-count] = nums[i]; } } return len-count; }

计算删除的个数