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 78af66a commit 3caffddCopy full SHA for 3caffdd
Remove Duplicates from Sorted Array/Remove_Duplicates_from_Sorted_Array.py
@@ -0,0 +1,32 @@
1
+# 第一种思路
2
+# 76ms 60.32%
3
+class Solution:
4
+ def removeDuplicates(self, nums):
5
+ """
6
+ :type nums: List[int]
7
+ :rtype: int
8
9
+ index = 1
10
+ while index < len(nums):
11
+ if nums[index] == nums[index - 1]:
12
+ del nums[index]
13
+ else:
14
+ index += 1
15
+ return len(nums)
16
+
17
+# 第二种思路,双指针法
18
+# 60ms 98.07
19
20
21
22
23
24
25
+ if not nums:
26
+ return 0
27
+ i = 0
28
+ for j in range(1, len(nums)):
29
+ if nums[j] != nums[i]:
30
+ i += 1
31
+ nums[i] = nums[j]
32
+ return i + 1
0 commit comments