
提示文章寫完后目錄可以自動生成如何生成可參考右邊的幫助文檔文章目錄刪除鏈表中給定的節點題目邊界條件如果要刪除的值,正好是是頭結點的value, 我們就需要找到第一個不需要刪的位置代碼刪除鏈表中給定的節點https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/題目邊界條件如果要刪除的值,正好是是頭結點的value, 我們就需要找到第一個不需要刪的位置代碼packageclass03;publicclassCode02_DeleteGivenValue{publicclassListNode{intval;ListNodenext;ListNode(intx){valx;}}// head deleteNode(head, 2);publicListNodedeleteNode(ListNodehead,intval){// head來到第一個不需要刪的位置while(head!null){if(head.val!val){break;}headhead.next;}// 1 ) head null// 2 ) head ! nullListNodeprehead;ListNodecurhead;while(cur!null){if(cur.valval){pre.nextcur.next;}else{precur;}curcur.next;}returnhead;}}