Stupid solution with python

  • 0
    class Solution(object):
        def removeElement(self, nums, val):
            cnt = 0
            for seq in range(len(nums)):
                if nums[seq] != val and cnt != 0:
                    nums[seq-cnt] = nums[seq]
                elif nums[seq] == val:
                    cnt += 1
            return len(nums) - cnt

Log in to reply

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