diff --git "a/2109020142/chapter2/\347\247\273\351\231\244\351\223\276\350\241\250\345\205\203\347\264\240" "b/2109020142/chapter2/\347\247\273\351\231\244\351\223\276\350\241\250\345\205\203\347\264\240" new file mode 100644 index 0000000000000000000000000000000000000000..bc7a1c110af1db1c990d7b31ea038000482cff1b --- /dev/null +++ "b/2109020142/chapter2/\347\247\273\351\231\244\351\223\276\350\241\250\345\205\203\347\264\240" @@ -0,0 +1,33 @@ +class Solution { + public ListNode removeElements(ListNode head, int val) { + if(head==null) + return null; + if(head.val==val&&head.next==null) + return null; + if(head.val!=val&&head.next==null) + return head; + ListNode cur=null; + while(head!=null) + { + if(head.val==val) + { + + head=head.next; + } + else { + cur=head; + break; + } + } + //if(head.val!=val&&head.next!=null) + + while(cur!=null) + { + if(cur.next!=null&&cur.next.val==val) + cur.next=cur.next.next; + else + cur=cur.next; + } + return head; + } +} \ No newline at end of file