Python, for rare elements to remove

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

Log in to reply

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