classSolution: defremoveElement(self, nums,val): length = len(nums) steps = 0 for i in range(length): while(i+steps < length and val == nums[i]): steps += 1 nums.pop(i) if i+ steps >= length: break
publicintremoveElement(int[] nums, int val){ int i = 0; int n = nums.length; while (i < n) { if (nums[i] == val) { nums[i] = nums[n - 1]; // reduce array size by one n--; } else { i++; } } return n; }