public class Solution {

```
public int removeElement(int[] nums, int val) {
int j = nums.length - 1;
for(int i = 0; i <= j; i++) {
while(nums[j] == val) {
if(j == 0) return 0;
j--;
}
if(nums[i] == val && i < j) {
nums[i] = nums[j];
j--;
}
}
return j+1;
}
```

}