var removeElement = function(nums, val) {
let len = nums.length;
for(let i = 0; i < len; i++){
if(nums[i] == val){
if(i == len - 1)len--;
else{
for(let j = i; j < len - 1; j++){
nums[j] = nums[j + 1];
}
i--;
len--;
}
}
}
return len;
};
JS力扣刷题27. 移除元素
最新推荐文章于 2024-07-26 11:41:15 发布