Remove all elements from a linked list of integers that have value val.
Example:
1
2
3 > Input: 1->2->6->3->4->5->6, val = 6
> Output: 1->2->3->4->5
>
思路
pre —> 通过检验的Node
dummy —> 标记head pre, 防止head消失
Note:val相等的情况有可能连续出现,所以只有已验证 != val, 才能pre = pre.next
Note2: 如果写while pre.next
, 前面要有while pre
所以: while pre and pre.next
1 | # Definition for singly-linked list. |