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.
2 parents c342d7e + bf863d2 commit a908463Copy full SHA for a908463
problems/0027.移除元素.md
@@ -253,6 +253,27 @@ class Solution:
253
254
```
255
256
+``` python 3
257
+# 相向双指针法
258
+# 时间复杂度 O(n)
259
+# 空间复杂度 O(1)
260
+class Solution:
261
+ def removeElement(self, nums: List[int], val: int) -> int:
262
+ n = len(nums)
263
+ left, right = 0, n - 1
264
+ while left <= right:
265
+ while left <= right and nums[left] != val:
266
+ left += 1
267
+ while left <= right and nums[right] == val:
268
+ right -= 1
269
+ if left < right:
270
+ nums[left] = nums[right]
271
272
273
+ return left
274
+
275
+```
276
277
### Go:
278
279
```go
0 commit comments