80. Remove Duplicates from Sorted Array II

Posted warmland

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了80. Remove Duplicates from Sorted Array II相关的知识,希望对你有一定的参考价值。

就是比之前的多一个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的主要内容,如果未能解决你的问题,请参考以下文章