标签:
思路:维护头和尾指针,头指针始终指向最后一个不重复的数字,尾指针不断向数组尾部探索找到不重复的值之后将其拷贝到头指针
class Solution {public:int removeDuplicates(int A[], int n) {if (n <= 1){return n;}int count = 1, head = 0, tail = 1;while (tail < n){while (A[tail] == A[head])tail++;if (tail < n){A[++head] = A[tail++];count++;}}return count;}};
Remove Duplicates from Sorted Array
标签:
原文地址:http://www.cnblogs.com/flyjameschen/p/4382964.html