赞
踩
- public class S_203 {
- public ListNode removeElements(ListNode head, int val) {
- // 为空
- if (head == null)
- return null;
- // 当不为空 且链表值等于给定值时
- while (head != null && head.val == val) {
- // 位移一位
- head = head.next;
- }
-
- ListNode node = head;
-
- while (node.next != null) {
- if (node.next.val == val)
- node.next = node.next.next;
- else
- node = node.next;
- }
- return head;
- }
- }
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。