Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8aa6a46

Browse files
🐱(array): 80. 删除排序数组中的重复项 II
精简解法
1 parent ee27089 commit 8aa6a46

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

‎docs/data-structure/array/README.md‎

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,23 +1016,14 @@ class Solution(object):
10161016

10171017
```python
10181018
# 这个好理解一些
1019-
class Solution(object):
1020-
def removeDuplicates(self, nums):
1021-
"""
1022-
:type nums: List[int]
1023-
:rtype: int
1024-
"""
1025-
length = len(nums)
1026-
1027-
if length <= 2:
1028-
return length
1029-
1019+
class Solution:
1020+
def removeDuplicates(self, nums: List[int]) -> int:
10301021
i = 0
1031-
for j in range(2, length):
1022+
for j in range(2, len(nums)):
10321023
if nums[i] != nums[j]:
10331024
nums[i + 2] = nums[j]
1034-
i = i + 1
1035-
1025+
i += 1
1026+
# i 指向最后一个被交换的元素
10361027
return i + 2
10371028
```
10381029

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /