Skip to content

Commit 063ad60

Browse files
committed
Solution to issue #46
Signed-off-by: allwells <aleenfestus@gmail.com>
1 parent 19576c9 commit 063ad60

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

0027/RemoveElements.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33

44
class Solution:
5-
65
def removeElement(self, nums: List[int], val: int) -> int:
7-
for i in nums:
8-
# check if val is in nums list
9-
if val in nums:
10-
# removes the val from nums list
11-
nums.remove(val)
6+
k = 0
7+
8+
for n in range(len(nums)):
9+
10+
if nums[n] != val:
11+
nums[k] = nums[n]
12+
k += 1
1213

13-
return nums # returns nums list with remaining elements
14+
return k

0 commit comments

Comments
 (0)