Re: [閒聊] 每日LeetCode已回收

看板Marginalman作者 (みけねこ的鼻屎)時間3年前 (2022/10/13 09:12), 3年前編輯推噓6(604)
留言10則, 7人參與, 3年前最新討論串44/719 (看更多)
237. Delete Node in a Linked List 給予一個node,從該鏈結串列刪除這個node的值。 Example: https://assets.leetcode.com/uploads/2020/09/01/node1.jpg
思路: 1.因為題目說提供的node一定不是最後一個,所以直接改他的值當作新的下個節點 2.https://i.imgur.com/Zq0iBJK.jpeg
JavaCode: class Solution { public void deleteNode(ListNode node) { node.val = node.next.val; node.next = node.next.next; } } 其實我看不懂這題再考三小這題為啥是Medium? 題目要我們刪除節點還不給我們頭節點 我倒讚了 這個月題目是不是不太行 -- https://i.imgur.com/7bZXdBG.jpg
-- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.160.89.219 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1665623565.A.BA6.html

10/13 09:29, 3年前 , 1F
大師
10/13 09:29, 1F

10/13 09:30, 3年前 , 2F
你這解法太粗暴惹
10/13 09:30, 2F

10/13 09:31, 3年前 , 3F
而且也不是真正意義上的刪除ㄅ 只是指不到?
10/13 09:31, 3F

10/13 09:32, 3年前 , 4F
理想做法應該是pop出來?
10/13 09:32, 4F
Delete the given node. Note that by deleting the node, we do not mean removing it from memory. We mean: * The value of the given node should not exist in the linked list. * The number of nodes in the linked list should decrease by one. * All the values before node should be in the same order. * All the values after node should be in the same order. ※ 編輯: Rushia (1.160.89.219 臺灣), 10/13/2022 09:36:07

10/13 09:47, 3年前 , 5F
應該是因為平常linked list的題目都會要求不能改value
10/13 09:47, 5F

10/13 09:47, 3年前 , 6F
這題想提醒你一下而已
10/13 09:47, 6F

10/13 10:26, 3年前 , 7F
大師
10/13 10:26, 7F

10/13 10:45, 3年前 , 8F
這樣原本的node(1),不就沒人指了?
10/13 10:45, 8F

10/13 11:36, 3年前 , 9F
在鏈結串列裡面 沒人指就和刪除差不多了 對ㄚ
10/13 11:36, 9F

10/13 18:53, 3年前 , 10F
會佔用記憶體吧 嗎
10/13 18:53, 10F
文章代碼(AID): #1ZHsODkc (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1ZHsODkc (Marginalman)