題目大意: 給一個數組,指定一個值讓其移到後面去,其他的按順序移到前面,並返回移除指定值剩餘數的個數~
比較easy,遍歷一遍,等於指定的不走,不等於就賦值往後走~
public class Solution027 {
public int removeElement(int[] nums, int val) {
int index = 0;
for(int i = 0; i < nums.length; i ++){
if(nums[i] != val)
nums[index++] = nums[i];
}
return index;
}
}