203. Remove Linked List Elements(链表)
2017-08-22 10:27
429 查看
https://leetcode.com/problems/remove-linked-list-elements/description/
题目:删除链表中的元素
思路:直接用2个指针即可。
题目:删除链表中的元素
思路:直接用2个指针即可。
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode* removeElements(ListNode* head, int val) { ListNode* dummy = new ListNode(0); dummy->next = head; head = dummy; while (head->next != NULL) { if (head->next->val == val) { head->next = head->next->next; } else { head = head->next; } } return dummy->next; } };
相关文章推荐
- 【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(链表操作)
- leetcode_c++:链表:Remove Linked List Elements(203)
- Leetcode 203 Remove Linked List Elements 链表
- [LeetCode-203] Remove Linked List Elements(链表节点删除)
- LeetCode 203 Remove Linked List Elements(移除链表元素)(*)
- 203. Remove Linked List Elements
- 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 203:Remove Linked List Elements
- 203. Remove Linked List Elements
- [leetcode203]Remove Linked List Elements
- 203. Remove Linked List Elements
- leetcode 203 Remove Linked List Elements
- 203. Remove Linked List Elements