Simple python solution 44ms


  • 1

    class Solution(object):
    def removeElement(self, nums, val):
    while(val in nums):
    nums.remove(val)
    return len(nums)

        """
        :type nums: List[int]
        :type val: int
        :rtype: int
        """

  • 0
    S

    not properly formatted


  • 2
    S
    class Solution(object):
        def removeElement(self, nums, val):
            i, j = 0, 0
            while i < len(nums):
                if nums[i] != val:
                    nums[j] = nums[i]
                    j += 1
                i += 1
            nums = nums[:j]
            return len(nums)

Log in to reply
 

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