标签:
就是比之前的多一个flag记录有没有重复过一次
1 public int removeDuplicates(int[] nums) { 2 if(nums == null || nums.length == 0) { 3 return 0; 4 } 5 boolean flag = false; 6 int index = 1; 7 for(int i = 1; i < nums.length; i++) { 8 if(nums[i-1] == nums[i]) { 9 if(flag == false) { 10 flag = true; 11 nums[index++] = nums[i]; 12 } 13 } else { 14 nums[index++] = nums[i]; 15 flag = false; 16 } 17 } 18 return index; 19 }
80. Remove Duplicates from Sorted Array II
标签:
原文地址:http://www.cnblogs.com/warmland/p/5348853.html