https://oj.leetcode.com/problems/remove-duplicates-from-sorted-array/
用一个cnt记录不重复的部分,后面每遇到不重复的cnt++即可。
class Solution { public: int removeDuplicates(int A[], int n) { if (n==0) return 0; int last=A[0]-1; int count=1; for(int i=0;i<n;i++){ if(A[count-1]!=A[i]) { A[count++]=A[i]; } } return count; } };
LeetCode-Remove Duplicates from Sorted Array-从有序数组移除重复-简单逻辑
原文:http://www.cnblogs.com/yangsc/p/4036348.html