leetcode 80 Remove Duplicates from Sorted Array II (有序数组去除重复元素)

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 1, 1, 2, 2 and 3. It doesn’t matter what you leave beyond the new length.

Subscribe to see which companies asked this question.

题意:一个有序数组,每个元素最多出现两次,如果大于两次,把多的去掉,返回去掉后的数组长度len,以及要求数组前len是去掉那些元素之后的元素。//语死早。。看原题好了。。

思路:排序了还不是随便搞? 没要求空间再开一个标记空间。。。O(1)空间的话。。就乱搞一下?

 

 

作者: CrazyKK

ex-ACMer@hust,stackoverflow-engineer@sensetime

说点什么

您将是第一位评论人!

提醒
wpDiscuz