27. 移除元素

题目链接

代码

class Solution {
    public int removeElement(int[] nums, int val) {
        int fast = 0,
            slow = 0;
        for( ; fast<nums.length; fast++) {
            if (nums[fast] != val) {
                nums[slow++] = nums[fast];
            }
        }
        return slow;
    }
}
posted @ 2022-09-13 21:37  jarico  阅读(23)  评论(0)    收藏  举报