LeetCode 80. Remove Duplicates from Sorted Array II

来源:互联网 发布:卖家被淘宝封号前预兆 编辑:程序博客网 时间:2024/06/13 10:19

和LeetCode 26. Remove Duplicates from Sorted Array相似

在升序数组中,每个数字最多只能出现2次。


代码:

class Solution {public:    int removeDuplicates(int A[], int n)     {    int length = 0;    for (int i=0; i < n; ){A[length ++] = A[i ++];if (i<n && A[i-1]==A[i]){A[length ++] = A[i ++];}for ( ; i<n && A[i]==A[i-1]; ++ i) {}}return length;    }};


0 0
原创粉丝点击