Inplace Remove Certain Value from an Array
- Given an array of numbers nums , and a number val , modify the array in place so that resulting array does not have the val .
- The array should be modified in place, and the function should return the number of eligible items in the new array.
Solution
class Solution(object): def removeElement(self, nums, val): """ :type nums: List[int] :type val: int :rtype: int """ searchIdx = 0 fillIdx = 0 rInt = 0 for searchIdx in range(len(nums)): if nums[searchIdx]==val: pass else: nums[fillIdx] = nums[searchIdx] fillIdx += 1 rInt += 1 return rInt