首页 > 其他 > 详细

LeetCode – Refresh – Remove Duplicates from Sorted Array II

时间:2015-03-22 16:30:30      阅读:340      评论:0      收藏:0      [点我收藏+]
 1 class Solution {
 2 public:
 3     int removeDuplicates(int A[], int n) {
 4         if (n < 3) return n;
 5         int index = 1, rec = A[0], count = 0;
 6         for (int i = 1; i < n; i++) {
 7             if (A[i] == rec) {
 8                 if (count < 1) {
 9                     A[index++] = A[i];
10                     count++;
11                 }
12             } else {
13                 A[index++] = A[i];
14                 rec = A[i];
15                 count = 0;
16             }
17         }
18         return index;
19     }
20 };

 

LeetCode – Refresh – Remove Duplicates from Sorted Array II

原文:http://www.cnblogs.com/shuashuashua/p/4357483.html

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