ShannonHung / ShannonHung.github.io

2 stars 0 forks source link

LeetCode #19 Remove Nth Node From End of List - 刷題之旅 | Shannon's Blog 🐟 技術 | 生活 | 旅行 #118

Open ShannonHung opened 2 months ago

ShannonHung commented 2 months ago

https://shannonhung.github.io/posts/leetcode-19-remove-nth-node-from-end-of-list/

1 題目描述 簡單來說,就是給定一個 linked list 和一個數字 n,要求刪除倒數第 n 個節點,並返回新的 linked list。 2 解法 2.1 我的解法 一開始想到的做法: 把所有位置的訊息存在一個 dict 裡面 然後因為已經遍歷過一次知道整個長度,直接尋找到要刪除的節點的前一個進行刪除。 12345678910111213141516171819202122232425