1 class Solution { 2 public: 3 int removeDuplicates(int A[], int n) { 4 if (n < 2) return n; 5 int rec = A[0], index = 1; 6 for (int i = 1; i < n; i++) { 7 if (A[i] != rec) { 8 A[index++] = A[i]; 9 rec = A[i];10 }11 }12 return index;13 }14 };
本文共 402 字,大约阅读时间需要 1 分钟。
1 class Solution { 2 public: 3 int removeDuplicates(int A[], int n) { 4 if (n < 2) return n; 5 int rec = A[0], index = 1; 6 for (int i = 1; i < n; i++) { 7 if (A[i] != rec) { 8 A[index++] = A[i]; 9 rec = A[i];10 }11 }12 return index;13 }14 };
转载于:https://www.cnblogs.com/shuashuashua/p/4357475.html