Remove Element
Question
Example:
Hint
Answer
solution1:
class Solution(object):
def removeElement(self, nums, val):
"""
:type nums: List[int]
:type val: int
:rtype: int
"""
i, last = 0, len(nums) - 1
while i <= last:
if nums[i] == val:
nums[i], nums[last] = nums[last], nums[i]
last -= 1
else:
i += 1
return last + 1solution2:(I prefer this one, cause it use the python advantage:list's function remove)
Knowledge:
Last updated