给定一个单链表和一个val,删除链表中所有值为val的节点,比如:1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6,val = 6,则返回1 --> 2 --> 3 --> 4 --> 5。ListNode* removeElements(ListNode* head, int val) { if(head == NULL) return head; ListNode *pHead = new ListNode(0); pHead->next = head; ListNode *pre = pHead; ListNode *cur = head; while(cur) { if(cur->val == val) { ListNode *tmp = cur; pre->next = cur->next; cur = cur->next; delete tmp; } else { pre = pre->next; cur = cur->next; } } return pHead->next; }