File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,48 @@ ListNode deleteDuplicates(ListNode head) {
66
66
67
67
![ labuladong] ( ../pictures/labuladong.png )
68
68
69
+ [ eric wang] ( https://www.github.com/eric496 ) 提供有序数组 Python3 代码
70
+
71
+ ``` python
72
+ def removeDuplicates (self , nums : List[int ]) -> int :
73
+ n = len (nums)
74
+
75
+ if n == 0 :
76
+ return 0
77
+
78
+ slow, fast = 0 , 1
79
+
80
+ while fast < n:
81
+ if nums[fast] != nums[slow]:
82
+ slow += 1
83
+ nums[slow] = nums[fast]
84
+
85
+ fast += 1
86
+
87
+ return slow + 1
88
+ ```
89
+
90
+ [ eric wang] ( https://www.github.com/eric496 ) 提供有序链表 Python3 代码
91
+
92
+ ``` python
93
+ def deleteDuplicates (self , head : ListNode) -> ListNode:
94
+ if not head:
95
+ return head
96
+
97
+ slow, fast = head, head.next
98
+
99
+ while fast:
100
+ if fast.val != slow.val:
101
+ slow.next = fast
102
+ slow = slow.next
103
+
104
+ fast = fast.next
105
+
106
+ # 断开与后面重复元素的连接
107
+ slow.next = None
108
+ return head
109
+ ```
110
+
69
111
[ 上一篇:如何高效解决接雨水问题] ( ../高频面试系列/接雨水.md )
70
112
71
113
[ 下一篇:如何寻找最长回文子串] ( ../高频面试系列/最长回文子串.md )
You can’t perform that action at this time.
0 commit comments