[leetcode] Remove Duplicates from Sorted Array II
Remove Duplicates from Sorted Array II Follow up for “Remove Duplicates”: What if duplicates are allowed at most twice? For example, Given sorted array A = [1,1,1,2,2,3], Your function should return length = 5, and A is now [1,1,2,2,3]. 很奇怪的题,和此题的第一代没有本质区别。 只要增加一个变量count记录当前已经出现的相同数字的个数。 如果count>2,不移动start,如果小于等于2,copy A[i] to A[start++]。 class Solution { public: int […]