Remove Element 2021-03-07 22:05
public static int removeElement(int[] nums, int val) {
int j = 0;
for (int i = 0; i < nums.length; i++) {
if (nums[i] == val) {
j++;
} else {
nums[i - j] = nums[i];
}
}
return nums.length - j;
}
Runtime | Memory |
---|---|
0 ms | 37.2 MB |
EOF