标签:跳过 turn list its 问题: for 存在 处理 node
Remove all elements from a linked list of integers that have value val.
Example:
Input: 1->2->6->3->4->5->6, val = 6 Output: 1->2->3->4->5
1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), next(NULL) {} 7 * }; 8 */ 9 class Solution { 10 public: 11 ListNode* removeElements(ListNode* head, int val) { 12 ListNode* dummy = new ListNode(0); 13 dummy->next = head; 14 ListNode* curr = dummy; 15 while(curr->next){ //always check its next point 16 if(curr->next->val==val){ 17 curr->next = curr->next->next; 18 } 19 else{ 20 curr=curr->next; 21 } 22 } 23 24 curr = dummy->next; 25 delete dummy; 26 return curr; 27 } 28 };
203. Remove Linked List Elements
标签:跳过 turn list its 问题: for 存在 处理 node
原文地址:https://www.cnblogs.com/ruisha/p/9368294.html