Re: [閒聊] 每日LeetCode已回收
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
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
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
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
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 44 之 719 篇):