Skip to content

Commit 4277415

Browse files
committed
🐱(array): 27. 移除元素
补充优化代码
1 parent 9dff793 commit 4277415

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

docs/data-structure/array/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,20 @@ class Solution:
371371
return res
372372
```
373373

374+
优化:
375+
376+
```python
377+
class Solution:
378+
def removeElement(self, nums: List[int], val: int) -> int:
379+
i = 0
380+
for j in range(len(nums)):
381+
if nums[j] == val:
382+
continue
383+
nums[i], nums[j] = nums[j], nums[i]
384+
i += 1
385+
return i
386+
```
387+
374388
#### **Go**
375389

376390
```go

0 commit comments

Comments
 (0)