/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* removeElements(struct ListNode* head, int val) {
struct ListNode** indirect = &head;
while (*indirect) {
if((*indirect)->val == val){
*indirect = (*indirect)->next;
}else{
indirect = &(*indirect)->next;
}
}
return head;
}
刷这题的时候突然想起Linus
的代码品味说,里面举例的也是删除链表节点,于是也照葫芦画瓢用了二级指针来做了这道题。