Fast & Concise Python Solution

  • 0

    def removeElement(self, nums, val):
    cur = 0
    if not nums:
    return 0
    for i in range(len(nums)):
    if nums[i] != val:
    nums[cur] = nums[i]
    cur += 1
    nums = nums[:cur]
    return len(nums)

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.