We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3dc31de commit c34b3f2Copy full SHA for c34b3f2
12. 删除有序数组中的重复项.md
@@ -11,18 +11,10 @@ class Solution:
11
def removeDuplicates(self, nums: List[int]) -> int:
12
#双指针法
13
n = len(nums)
14
- if n==1:
15
- return 1
16
- left = 0
17
- right = 1
18
- #循环终止条件
19
- while right < n:
20
- #如果不相等,将right位置的元素复制到left+1位置上,left后移一位
21
- if nums[right] != nums[left]:
22
- nums[left+1] = nums[right]
23
- left += 1
24
- #right后移一位
25
- right += 1
26
- #返回新数组长度
27
- return left+1
28
-```
+ i = 0
+ for j in range(n):
+ if nums[j] != nums[i]:
+ nums[i+1] = nums[j]
+ i +=1
+ return i+1
+```
0 commit comments