Leetcode Remove Duplicates from Sorted Array
class Solution { public: int removeDuplicates(int A[], int n) { int duplicate = 0; int i = 0; for(i = 0; i < n - 1; i++){ if(A[i] == A[i + 1]){ duplicate++; } else { A[i - duplicate + 1] = A[i + 1]; } } return n - duplicate; } };
posted on 2017-05-06 14:48 cynchanpin 阅读(131) 评论(0) 编辑 收藏 举报