80. 删除有序数组中的重复项 II
为保证权益,题目请参考 80. 删除有序数组中的重复项 II(From LeetCode).
解决方案1
Python
python
# 80. 删除有序数组中的重复项 II
# https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii/
from typing import List
class Solution:
def removeDuplicates(self, nums: List[int]) -> int:
for i in range(len(nums)-1, 1, -1):
if nums[i] == nums[i-1] and nums[i] == nums[i-2]:
nums.pop(i)
return len(nums)
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11