LeetCode 80 Remove Duplicates from Sorted Array II 题解
1.题目:
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
题意:
输入一个有序数组,去除数组中重复的元素,(允许两个重复的存在),并输出最后的元素的个数。
2.解题思路:
标记一个flag,注意边界条件
3.代码
1 |
|