LeetCode203——Remove Linked List Elements
2015-05-24 22:51
267 查看
Remove all elements from a linked list of integers that have value val.
Example Given: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6 Return: 1 --> 2 --> 3 --> 4 --> 5
Credits: Special thanks to @mithmatt for adding this problem and creating all test cases.
实现:
Example Given: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6 Return: 1 --> 2 --> 3 --> 4 --> 5
Credits: Special thanks to @mithmatt for adding this problem and creating all test cases.
实现:
[code]ListNode* removeElements(ListNode* head, int val) { ListNode* currNode = head; while (true) { if (head == NULL) return NULL; if (currNode->val != val) break; currNode = currNode->next; head = currNode; } while (currNode->next) { if (currNode->next->val == val) { currNode->next = currNode->next->next; } else { currNode = currNode->next; } } return head; }
相关文章推荐
- LeetCode 203:Remove Linked List Elements
- <LeetCode OJ> Remove Linked List Elements【203】
- LeetCode 203 Remove Linked List Elements(链表操作)
- LeetCode:203. Remove Linked List Elements
- LeetCode(203)——Remove Linked List Elements
- leetcode 203 Remove Linked List Elements
- leetcode之203. Remove Linked List Elements(C++解法)
- leetcode 203 Remove Linked List Elements
- Leetcode(203):Remove Linked List Elements
- 【LeetCode】237 & 203 - Delete Node in a Linked List & Remove Linked List Elements
- leetcode 203:Remove Linked List Elements
- LeetCode - 83/82/203/19 - Remove Elements from Linked List
- LeetCode笔记:203. Remove Linked List Elements
- leetcode[203]:Remove Linked List Elements
- [leetcode 203] Remove Linked List Elements
- LeetCode-Easy部分中标签为LinkedList 203 Remove Linked List Elements
- [leetcode-203]Remove Linked List Elements(c)
- leetcode——203——Remove Linked List Elements
- leetcode 203 Remove Linked List Elements
- leetcode203---Remove Linked List Elements