short python solution


  • 0
    G
    class Solution(object):
        def removeElement(self, nums, val):
            """
            :type nums: List[int]
            :type val: int
            :rtype: int
            """
            i, j, n = 0, 0, len(nums)
            while j < n:
                if nums[j] != val:
                    nums[i] = nums[j]
                    i += 1
                j += 1
            return i
    

Log in to reply
 

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