diff --git "a/2209040023/chap2/lc-2\347\247\273\351\231\244\351\223\276\350\241\250\345\205\203\347\264\240.cpp" "b/2209040023/chap2/lc-2\347\247\273\351\231\244\351\223\276\350\241\250\345\205\203\347\264\240.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..220bca0e34a564a3baba92e85bc58a04db926af1 --- /dev/null +++ "b/2209040023/chap2/lc-2\347\247\273\351\231\244\351\223\276\350\241\250\345\205\203\347\264\240.cpp" @@ -0,0 +1,21 @@ +class Solution { +public: + ListNode* removeElements(ListNode* head, int val) { + ListNode *Head=new ListNode(0); //设置虚拟节点 + Head->next=head; + ListNode *cur=Head; + + while(cur->next!=NULL) + { + if(cur->next->val==val){ + ListNode *tmp=cur->next; + cur->next=cur->next->next; + delete tmp; + } + else cur=cur->next; + } + head=Head->next; + delete Head; + return head; + } +}; \ No newline at end of file