Given an array and a value, remove all instances of that value in place and return the new length.
The order of elements can be changed. It doesn't matter what you leave beyond the new length.
这个题的题意和上一个题貌似是一样的,使用了同样的方法。
1)
public class Solution {
public int removeElement(int[] nums, int elem) {
int i = 0;
for(int j = 0 ; j < nums.length ; j++){
if(nums[j] != elem){
nums[i] = nums[j];
i++;
}
}
return i;
}
}