027.Remove Element

Test cases

1
2
3
4
5
6
[3,2,2,3]
[3,3,3,3]
[3,2,3,3]
[3,2,1,0]
[1,2,2,3]
[1,2,3,4]

Solution 1: Accepted

This is an easy one.

1
2
3
4
5
6
7
8
9
10
public int removeElement(int[] nums, int val) {
int count = 0;
for(int i = 0; i < nums.length; i++) {
if (nums[i] != val) {
nums[count] = nums[i];
count++;
}
}
return count;
}