Remove Element

Today I did this Leetcode problem. The remove() function is in-place so we just have to use that to satisfy the requirements of this problem.

class Solution(object):
    def removeElement(self, nums, val):
        """
        :type nums: List[int]
        :type val: int
        :rtype: int
        """

        for i in range(nums.count(val)):  
            nums.remove(val) 
        return len(nums) 
Previous
Previous

Dynamic Arrays

Next
Next

Remove Duplicates from Sorted Array