最多n个相同的连续,那么就每隔n个检查下是否相等就0k了。。。

class Solution {
public:
    int removeDuplicates(int A[], int n) {
        if(n <= 2) return n;
        int cnt = 2;
        for(int i = 2 ; i < n ; i ++) {
            if(A[i] != A[cnt-2]) {
                A[cnt++] = A[i];
            }
        }
        return cnt;
    }
};

 

相关文章:

  • 2022-12-23
  • 2021-12-24
  • 2021-12-11
  • 2021-07-24
  • 2021-05-19
猜你喜欢
  • 2021-05-29
  • 2021-10-02
  • 2021-11-17
  • 2021-06-01
  • 2021-11-25
相关资源
相似解决方案