难度:medium

Follow up for "Remove Duplicates":
What if duplicates are allowed at most twice?

For example,
Given sorted array nums = [1,1,1,2,2,3],

Your function should return length = 5, with the first five elements of nums being 1122 and 3. It doesn't matter what you leave beyond the new length.

思路: 删除给定list里面重复超过两次以上的element,最后返回list的最终长度。

           此类题肯定是要用到hashtable,key对应的value是该数字出现的次数,当出现的次数超过两次,(注意顺序)先将value降至2,再删除原list中的element,最后修改while语句中的n。


leetcode80[medium]--Remove Duplicates from Sorted Array II



相关文章: