码迷,mamicode.com
首页 > 其他好文 > 详细

80. Remove Duplicates from Sorted Array II

时间:2016-04-03 07:08:02      阅读:101      评论:0      收藏:0      [点我收藏+]

标签:

就是比之前的多一个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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!