Skip to content

Commit f2e2479

Browse files
committed
Re-solve "Remove Element"
1 parent b61dd8f commit f2e2479

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/remove_element.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
class Solution:
22
def removeElement(self, nums: list[int], val: int) -> int:
3-
to_insert = 0
3+
i = 0
44

5-
for num in nums:
6-
if num != val:
7-
nums[to_insert] = num
8-
to_insert += 1
5+
for x in nums:
6+
if x == val:
7+
continue
8+
nums[i] = x
9+
i += 1
910

10-
return to_insert
11+
return i

0 commit comments

Comments
 (0)