LeetCode - Remove Linked List Elements
2015-04-26 22:16
369 查看
删除链表中的指定元素。
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ public class Solution { public ListNode removeElements(ListNode head, int val) { if(head == null)return null; ListNode p,q; p = head.next; q = head; while(p!=null) { if(p.val == val) { q.next = p.next; p = p.next; } else { p = p.next; q = q.next; } } if(head.val == val) { head = head.next; } return head; } }
相关文章推荐
- Remove Linked List Elements -- leetcode
- Leetcode 203 Remove Linked List Elements
- LeetCode Remove Linked List Elements 链表
- LeetCode 之 Remove Linked List Elements
- leetcode-203 Remove Linked List Elements
- LeetCode 203 Remove Linked List Elements
- Leetcode学习(15)—— Remove Linked List Elements
- [LeetCode]203 Remove Linked List Elements
- Java [Leetcode 203]Remove Linked List Elements
- Leetcode[203]-Remove Linked List Elements
- LeetCode Remove Linked List Elements
- leetcode 203 -- Remove Linked List Elements
- LeetCode || Remove Linked List Elements
- Leetcode 之 Remove Linked List Elements
- 【LEETCODE】203-Remove Linked List Elements
- Leetcode: Remove Linked List Elements
- [leetcode]: 203. Remove Linked List Elements
- LeetCode 203 Remove Linked List Elements
- leetcode Remove Linked List Elements
- [LeetCode] Remove Linked List Elements