0203. Remove Linked List Elements

203. Remove Linked List Elements #

题目 #

给定链表头节点head和一个整数val,删除链表中所有满足Node.val == val的节点,并返回新的头节点。

思路 #

代码 #

class Solution {
    public void moveZeros(int[] nums) {
        int slow = 0, fast = 0;
        while (fast < nums.length) {
            if (nums[fast] != 0) nums[slow++] = nums[fast];
            fast += 1;
        }
        while (slow < nums.length) nums[slow++] = 0;
    }
}