首页 > 其他 > 详细

Remove Duplicates from Sorted Array II

时间:2014-02-13 14:53:07      阅读:315      评论:0      收藏:0      [点我收藏+]

Follow up for "Remove Duplicates":
What if duplicates are allowed at most twice?

bubuko.com,布布扣
 1 public class Solution {
 2     public int removeDuplicates(int[] A) {
 3         int len = A.length;
 4         if(len<=2) return len;
 5         int p1 = 1;
 6         int p2 =1;
 7         int count =1;
 8         while(p2<len){
 9             if(A[p2]==A[p2-1]){
10                 if(count>=2){
11                     p2++;
12                     continue;
13                 }
14                 else{
15                     count++;
16                 }
17             }
18             else{
19                 count=1;
20             }
21             A[p1] = A[p2];
22             p1++;
23             p2++;
24         }
25         return p1;
26     }
27 }
View Code

Remove Duplicates from Sorted Array II

原文:http://www.cnblogs.com/krunning/p/3547424.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!