去掉有序数组中的重复元素:
int RemoveDuplates(int A[], int nCnt) { int nNewLen = 0; int j = 0; for (int i = 0, j = 0; i < nCnt && j < nCnt; i++) { while(j < nCnt && A[i] == A[j]) j++; if( j > i + 1 && j < nCnt) A[i + 1] = A[j]; nNewLen++; } return nNewLen; }
去掉有序数组中的重复元素:
int RemoveDuplates(int A[], int nCnt) { int nNewLen = 0; int j = 0; for (int i = 0, j = 0; i < nCnt && j < nCnt; i++) { while(j < nCnt && A[i] == A[j]) j++; if( j > i + 1 && j < nCnt) A[i + 1] = A[j]; nNewLen++; } return nNewLen; }
转载于:https://www.cnblogs.com/algorithmic/p/3664275.html