<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Depth-First-Search on</title><link>https://h30306.github.io/blog/zh-tw/tags/depth-first-search/</link><description>Recent content in Depth-First-Search on</description><generator>Hugo -- gohugo.io</generator><language>zh-tw</language><managingEditor>hwork0511@gmail.com (Wei Yi Chung)</managingEditor><webMaster>hwork0511@gmail.com (Wei Yi Chung)</webMaster><copyright>© 2026 Wei Yi Chung</copyright><lastBuildDate>Sun, 01 Nov 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://h30306.github.io/blog/zh-tw/tags/depth-first-search/index.xml" rel="self" type="application/rss+xml"/><item><title>LeetCode 2385: Amount of Time for Binary Tree to Be Infected</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-2385/</link><pubDate>Sun, 01 Nov 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-2385/</guid><description>LeetCode 2385 解題筆記：把樹轉成無向圖，從 start 做 BFS，層數減一就是分鐘數</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-2385/featured.png"/></item><item><title>LeetCode 2858: Minimum Edge Reversals So Every Node Is Reachable</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-2858/</link><pubDate>Sat, 31 Oct 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-2858/</guid><description>LeetCode 2858 解題筆記：換根 DP：先算以 0 為根要翻幾條邊，根移到小孩時，這條邊原本順向就 +1、逆向就 -1</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-2858/featured.png"/></item><item><title>LeetCode 834: Sum of Distances in Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-834/</link><pubDate>Sat, 31 Oct 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-834/</guid><description>LeetCode 834 解題筆記：換根 DP：先以 0 為根算子樹大小和 ans[0]，再用 ans[child] = ans[parent] - size + (n - size) 推到每個節點</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-834/featured.png"/></item><item><title>LeetCode 968: Binary Tree Cameras</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-968/</link><pubDate>Fri, 30 Oct 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-968/</guid><description>LeetCode 968 解題筆記：後序貪心，每個節點三種狀態：有相機、被覆蓋、沒被覆蓋；有小孩沒被覆蓋才放相機，最後根沒被覆蓋要補一台</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-968/featured.png"/></item><item><title>LeetCode 437: Path Sum III</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-437/</link><pubDate>Wed, 28 Oct 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-437/</guid><description>LeetCode 437 解題筆記：樹上的前綴和 + 雜湊表：先查 prefix - target 再把自己加進去，離開節點時要扣回來</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-437/featured.png"/></item><item><title>LeetCode 863: All Nodes Distance K in Binary Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-863/</link><pubDate>Wed, 28 Oct 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-863/</guid><description>LeetCode 863 解題筆記：先把樹轉成無向圖（補上往父節點的邊），再從 target BFS 走 k 步</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-863/featured.png"/></item><item><title>LeetCode 652: Find Duplicate Subtrees</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-652/</link><pubDate>Mon, 26 Oct 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-652/</guid><description>LeetCode 652 解題筆記：後序把每棵子樹編碼，出現第二次時加入答案；字串編碼最差 O(n^2)，改成 (值, 左 id, 右 id) 編號可到 O(n)</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-652/featured.png"/></item><item><title>LeetCode 297: Serialize and Deserialize Binary Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-297/</link><pubDate>Sun, 25 Oct 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-297/</guid><description>LeetCode 297 解題筆記：前序遍歷加上空節點標記就能唯一還原樹；反序列化用迭代器依序取值</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-297/featured.png"/></item><item><title>LeetCode 449: Serialize and Deserialize BST</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-449/</link><pubDate>Sun, 25 Oct 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-449/</guid><description>LeetCode 449 解題筆記：BST 只要存前序，不用空節點標記；反序列化帶著上下界遞迴，O(n)</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-449/featured.png"/></item><item><title>LeetCode 99: Recover Binary Search Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-99/</link><pubDate>Sun, 25 Oct 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-99/</guid><description>LeetCode 99 解題筆記：中序遍歷找逆序：第一次逆序的前一個、最後一次逆序的後一個，就是被交換的兩個節點</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-99/featured.png"/></item><item><title>LeetCode 124: Binary Tree Maximum Path Sum</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-124/</link><pubDate>Sat, 24 Oct 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-124/</guid><description>LeetCode 124 解題筆記：DFS 回傳往下的一條鏈，在每個節點用「左鏈 + 自己 + 右鏈」更新答案；負的鏈要丟掉</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-124/featured.png"/></item><item><title>LeetCode 1372: Longest ZigZag Path in a Binary Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-1372/</link><pubDate>Sat, 24 Oct 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-1372/</guid><description>LeetCode 1372 解題筆記：每個節點回傳兩個值：從這裡先往左、先往右的最長 zigzag；往左走接的是左小孩「先往右」的值</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-1372/featured.png"/></item><item><title>LeetCode 515: Find Largest Value in Each Tree Row</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-515/</link><pubDate>Sat, 24 Oct 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-515/</guid><description>LeetCode 515 解題筆記：BFS 層序遍歷，每層取最大值；初始值用 -inf</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-515/featured.png"/></item><item><title>LeetCode 687: Longest Univalue Path</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-687/</link><pubDate>Sat, 24 Oct 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-687/</guid><description>LeetCode 687 解題筆記：DFS 回傳往下同值的最長鏈（邊數），在每個節點用左 + 右更新答案</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-687/featured.png"/></item><item><title>LeetCode 314: Binary Tree Vertical Order Traversal</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-314/</link><pubDate>Thu, 22 Oct 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-314/</guid><description>LeetCode 314 解題筆記：BFS 帶著欄位編號，用 BFS 才能保證同一欄由上到下、同一列由左到右</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-314/featured.png"/></item><item><title>LeetCode 2973: Find Number of Coins to Place in Tree Nodes</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-2973/</link><pubDate>Sat, 12 Sep 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-2973/</guid><description>LeetCode 2973 解題筆記：三個數的最大乘積只可能是「最大的三個」或「最小的兩個 × 最大的一個」；每個子樹只回傳最小 2 個和最大 3 個，後序合併</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-2973/featured.png"/></item><item><title>LeetCode 1373: Maximum Sum BST in Binary Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-1373/</link><pubDate>Thu, 10 Sep 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-1373/</guid><description>LeetCode 1373 解題筆記：後序遍歷回傳 (總和, 最小值, 最大值, 是不是 BST)；左子樹的最大值 &amp;lt; 自己 &amp;lt; 右子樹的最小值才是 BST</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-1373/featured.png"/></item><item><title>LeetCode 988: Smallest String Starting From Leaf</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-988/</link><pubDate>Wed, 17 Apr 2024 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-988/</guid><description>LeetCode 988 解題筆記：DFS 時把字元加在字串前面，到葉子時就是「從葉子到根」的字串，取最小的</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-988/featured.png"/></item><item><title>LeetCode 113: Path Sum II</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-113/</link><pubDate>Fri, 18 Nov 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-113/</guid><description>LeetCode 113 解題筆記：回溯記錄目前的路徑，到葉子時總和等於目標就存一份複本；值可能是負的，不能提早剪枝</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-113/featured.png"/></item><item><title>LeetCode 116: Populating Next Right Pointers in Each Node</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-116/</link><pubDate>Fri, 18 Nov 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-116/</guid><description>LeetCode 116 解題筆記：完美二元樹，用上一層已經接好的 next 走過這一層：left.next = right，right.next = next.left；O(1) 額外空間</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-116/featured.png"/></item><item><title>LeetCode 117: Populating Next Right Pointers in Each Node II</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-117/</link><pubDate>Fri, 18 Nov 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-117/</guid><description>LeetCode 117 解題筆記：BFS 一層一層接 next；不是完全二元樹時，只看隔壁節點的小孩會斷掉</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-117/featured.png"/></item><item><title>LeetCode 129: Sum Root to Leaf Numbers</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-129/</link><pubDate>Fri, 18 Nov 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-129/</guid><description>LeetCode 129 解題筆記：往下走時目前的數字乘 10 加上節點的值，到葉子時加進總和</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-129/featured.png"/></item><item><title>LeetCode 2331: Evaluate Boolean Binary Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-2331/</link><pubDate>Fri, 18 Nov 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-2331/</guid><description>LeetCode 2331 解題筆記：葉子是 0 或 1，內部節點 2 是 OR、3 是 AND，後序遞迴計算</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-2331/featured.png"/></item><item><title>LeetCode 236: Lowest Common Ancestor of a Binary Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-236/</link><pubDate>Fri, 18 Nov 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-236/</guid><description>LeetCode 236 解題筆記：遞迴回傳子樹裡找到的 p 或 q；左右都找到代表在這裡分岔，這個節點就是 LCA</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-236/featured.png"/></item><item><title>LeetCode 1379: Find a Corresponding Node of a Binary Tree in a Clone of That Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-1379/</link><pubDate>Thu, 17 Nov 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-1379/</guid><description>LeetCode 1379 解題筆記：兩棵樹同時走，原樹走到 target 時，複製樹上的同一個位置就是答案；比的是節點本身</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-1379/featured.png"/></item><item><title>LeetCode 337: House Robber III</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-337/</link><pubDate>Wed, 16 Nov 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-337/</guid><description>LeetCode 337 解題筆記：樹上 DP，每個節點回傳（搶它、不搶它）的最大值；不是一層一層交錯搶</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-337/featured.png"/></item><item><title>LeetCode 133: Clone Graph</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-133/</link><pubDate>Sun, 30 Oct 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-133/</guid><description>LeetCode 133 解題筆記：DFS 時用雜湊表記住舊節點對應的新節點，遇到已經複製過的就直接回傳，避免無限遞迴；空圖回傳 None</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-133/featured.png"/></item><item><title>LeetCode 417: Pacific Atlantic Water Flow</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-417/</link><pubDate>Sun, 30 Oct 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-417/</guid><description>LeetCode 417 解題筆記：反過來從海邊往內走，只能走到不比自己低的格子；兩個海都走得到的格子就是答案</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-417/featured.png"/></item><item><title>LeetCode 695: Max Area of Island</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-695/</link><pubDate>Sun, 30 Oct 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-695/</guid><description>LeetCode 695 解題筆記：每遇到一個沒走過的 1 就 DFS 整座島，數格子數，取最大值；格子是整數 1，不是字串</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-695/featured.png"/></item><item><title>LeetCode 1448: Count Good Nodes in Binary Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-1448/</link><pubDate>Sat, 29 Oct 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-1448/</guid><description>LeetCode 1448 解題筆記：DFS 往下傳路徑上的最大值，節點的值大於等於它就是好節點</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-1448/featured.png"/></item><item><title>LeetCode 199: Binary Tree Right Side View</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-199/</link><pubDate>Sat, 29 Oct 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-199/</guid><description>LeetCode 199 解題筆記：層序遍歷，每一層最右邊的節點就是從右邊看得到的</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-199/featured.png"/></item><item><title>LeetCode 230: Kth Smallest Element in a BST</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-230/</link><pubDate>Sat, 29 Oct 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-230/</guid><description>LeetCode 230 解題筆記：BST 的中序遍歷是由小到大，迭代中序走到第 k 個就停</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-230/featured.png"/></item><item><title>LeetCode 98: Validate Binary Search Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-98/</link><pubDate>Sat, 29 Oct 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-98/</guid><description>LeetCode 98 解題筆記：每個節點都有一個合法範圍（下界, 上界），往左走上界變成自己、往右走下界變成自己；只比父子不夠</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-98/featured.png"/></item><item><title>LeetCode 79: Word Search</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-79/</link><pubDate>Wed, 26 Oct 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-79/</guid><description>LeetCode 79 解題筆記：從每一格開始回溯，往四個方向比對下一個字元，走過的格子暫時標記，回溯時還原；先用字元次數剪枝</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-79/featured.png"/></item><item><title>LeetCode 1022: Sum of Root To Leaf Binary Numbers</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-1022/</link><pubDate>Tue, 27 Sep 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-1022/</guid><description>LeetCode 1022 解題筆記：往下走時目前的數字乘 2 加上節點的值，到葉子時加進總和</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-1022/featured.png"/></item><item><title>LeetCode 938: Range Sum of BST</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-938/</link><pubDate>Mon, 26 Sep 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-938/</guid><description>LeetCode 938 解題筆記：利用 BST 剪枝，節點比 low 小就只往右，比 high 大就只往左，在範圍內才加</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-938/featured.png"/></item><item><title>LeetCode 965: Univalued Binary Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-965/</link><pubDate>Mon, 26 Sep 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-965/</guid><description>LeetCode 965 解題筆記：每個節點的值都要等於根的值；遞迴時比的是值，不是遞迴回傳的布林值</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-965/featured.png"/></item><item><title>LeetCode 993: Cousins in Binary Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-993/</link><pubDate>Mon, 26 Sep 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-993/</guid><description>LeetCode 993 解題筆記：堂兄弟要同一層、但父節點不同；DFS 記錄 x 和 y 的深度與父節點再比較</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-993/featured.png"/></item><item><title>LeetCode 897: Increasing Order Search Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-897/</link><pubDate>Sun, 25 Sep 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-897/</guid><description>LeetCode 897 解題筆記：中序遍歷，依序把節點接到一條只有右小孩的鏈上，左小孩設成 None；dummy 和移動的尾巴要分開</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-897/featured.png"/></item><item><title>LeetCode 872: Leaf-Similar Trees</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-872/</link><pubDate>Sat, 17 Sep 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-872/</guid><description>LeetCode 872 解題筆記：用 DFS 由左到右收集葉子；BFS 收集的順序是一層一層，不是由左到右</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-872/featured.png"/></item><item><title>LeetCode 783: Minimum Distance Between BST Nodes</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-783/</link><pubDate>Tue, 06 Sep 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-783/</guid><description>LeetCode 783 解題筆記：BST 的中序是由小到大，最小差一定出現在中序相鄰的兩個值之間；記住前一個值逐一比較</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-783/featured.png"/></item><item><title>LeetCode 733: Flood Fill</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-733/</link><pubDate>Sat, 03 Sep 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-733/</guid><description>LeetCode 733 解題筆記：從起點 DFS / BFS，四個方向上跟起點原本顏色相同的格子都換成新顏色；新舊顏色相同時直接回傳</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-733/featured.png"/></item><item><title>LeetCode 637: Average of Levels in Binary Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-637/</link><pubDate>Mon, 29 Aug 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-637/</guid><description>LeetCode 637 解題筆記：層序遍歷，每層加總除以節點數</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-637/featured.png"/></item><item><title>LeetCode 653: Two Sum IV - Input is a BST</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-653/</link><pubDate>Mon, 29 Aug 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-653/</guid><description>LeetCode 653 解題筆記：遍歷時用集合記看過的值，k - val 已經在集合裡就找到了</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-653/featured.png"/></item><item><title>LeetCode 671: Second Minimum Node In a Binary Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-671/</link><pubDate>Mon, 29 Aug 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-671/</guid><description>LeetCode 671 解題筆記：根就是最小值；第二小值是整棵樹裡第一個比根大的最小值，值等於根的子樹才需要往下找</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-671/featured.png"/></item><item><title>LeetCode 606: Construct String from Binary Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-606/</link><pubDate>Sun, 28 Aug 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-606/</guid><description>LeetCode 606 解題筆記：前序輸出，左子樹空但右子樹不空時要留一個空括號 ()，右子樹空時可以省略</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-606/featured.png"/></item><item><title>LeetCode 559: Maximum Depth of N-ary Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-559/</link><pubDate>Sat, 27 Aug 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-559/</guid><description>LeetCode 559 解題筆記：深度等於 1 加上所有小孩深度的最大值；沒有小孩時是 1</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-559/featured.png"/></item><item><title>LeetCode 563: Binary Tree Tilt</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-563/</link><pubDate>Sat, 27 Aug 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-563/</guid><description>LeetCode 563 解題筆記：後序回傳子樹的總和，每個節點的 tilt 是左右子樹總和的差，加進答案</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-563/featured.png"/></item><item><title>LeetCode 572: Subtree of Another Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-572/</link><pubDate>Sat, 27 Aug 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-572/</guid><description>LeetCode 572 解題筆記：對 root 的每一個節點都檢查一次「以它為根的子樹跟 subRoot 是否相同」；遞迴時要呼叫 isSubtree，不是只比左右小孩</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-572/featured.png"/></item><item><title>LeetCode 589: N-ary Tree Preorder Traversal</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-589/</link><pubDate>Sat, 27 Aug 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-589/</guid><description>LeetCode 589 解題筆記：N 叉樹的前序，先記錄自己，再依序處理每個小孩；遞迴結果要用 extend 攤平，不是 append 一個 list</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-589/featured.png"/></item><item><title>LeetCode 590: N-ary Tree Postorder Traversal</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-590/</link><pubDate>Sat, 27 Aug 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-590/</guid><description>LeetCode 590 解題筆記：後序是先每個小孩再自己；迭代時可以做「根、小孩由右到左」的前序再整個反轉</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-590/featured.png"/></item><item><title>LeetCode 501: Find Mode in Binary Search Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-501/</link><pubDate>Thu, 25 Aug 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-501/</guid><description>LeetCode 501 解題筆記：BST 中序是排序的，相同的值會連在一起；中序時數目前這段的長度，比最大值大就重設答案，一樣大就加入</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-501/featured.png"/></item><item><title>LeetCode 530: Minimum Absolute Difference in BST</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-530/</link><pubDate>Thu, 25 Aug 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-530/</guid><description>LeetCode 530 解題筆記：BST 的中序是由小到大，最小差一定出現在中序相鄰的兩個值之間；記住前一個值逐一比較</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-530/featured.png"/></item><item><title>LeetCode 543: Diameter of Binary Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-543/</link><pubDate>Thu, 25 Aug 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-543/</guid><description>LeetCode 543 解題筆記：直徑可能不經過根；後序回傳高度，同時在每個節點用「左高 + 右高」更新答案；算的是邊數</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-543/featured.png"/></item><item><title>LeetCode 463: Island Perimeter</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-463/</link><pubDate>Wed, 24 Aug 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-463/</guid><description>LeetCode 463 解題筆記：每格陸地貢獻 4 條邊，每跟上方或左方的陸地相鄰一次就少 2 條</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-463/featured.png"/></item><item><title>LeetCode 404: Sum of Left Leaves</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-404/</link><pubDate>Tue, 23 Aug 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-404/</guid><description>LeetCode 404 解題筆記：DFS 時告訴小孩自己是不是左小孩，只有「是左小孩而且是葉子」才加</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-404/featured.png"/></item><item><title>LeetCode 235: Lowest Common Ancestor of a Binary Search Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-235/</link><pubDate>Mon, 22 Aug 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-235/</guid><description>LeetCode 235 解題筆記：p、q 都比節點小就往左，都比節點大就往右，否則（一邊一個或其中一個就是自己）這個節點就是 LCA</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-235/featured.png"/></item><item><title>LeetCode 257: Binary Tree Paths</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-257/</link><pubDate>Mon, 22 Aug 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-257/</guid><description>LeetCode 257 解題筆記：DFS 帶著目前的路徑字串往下，到葉子時把整條路徑加進答案</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-257/featured.png"/></item><item><title>LeetCode 226: Invert Binary Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-226/</link><pubDate>Sun, 21 Aug 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-226/</guid><description>LeetCode 226 解題筆記：每個節點交換左右小孩；用同時指定，避免先改掉的那邊被拿來用</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-226/featured.png"/></item><item><title>LeetCode 145: Binary Tree Postorder Traversal</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-145/</link><pubDate>Sat, 20 Aug 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-145/</guid><description>LeetCode 145 解題筆記：迭代的後序遍歷，節點第一次彈出時標記後放回去，再依序推右、左小孩；第二次彈出才記錄</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-145/featured.png"/></item><item><title>LeetCode 110: Balanced Binary Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-110/</link><pubDate>Tue, 16 Aug 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-110/</guid><description>LeetCode 110 解題筆記：每一個節點的左右高度差都不能超過 1；後序回傳高度，不平衡時回傳 -1 一路傳上去</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-110/featured.png"/></item><item><title>LeetCode 111: Minimum Depth of Binary Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-111/</link><pubDate>Tue, 16 Aug 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-111/</guid><description>LeetCode 111 解題筆記：最小深度要到葉子才算；只有一邊有小孩時不能拿空的那邊（深度 0）當最小值</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-111/featured.png"/></item><item><title>LeetCode 112: Path Sum</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-112/</link><pubDate>Tue, 16 Aug 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-112/</guid><description>LeetCode 112 解題筆記：往下走時把 targetSum 減掉目前的值，到葉子時剛好是 0（或等於葉子的值）就成立</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-112/featured.png"/></item><item><title>LeetCode 100: Same Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-100/</link><pubDate>Tue, 02 Aug 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-100/</guid><description>LeetCode 100 解題筆記：兩邊都是空的才相同；一邊空一邊不空就不同；都不空時比值再遞迴比左右</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-100/featured.png"/></item><item><title>LeetCode 101: Symmetric Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-101/</link><pubDate>Tue, 02 Aug 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-101/</guid><description>LeetCode 101 解題筆記：左子樹跟右子樹互為鏡像：外側跟外側比、內側跟內側比；比的是值，不是節點本身</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-101/featured.png"/></item><item><title>LeetCode 104: Maximum Depth of Binary Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-104/</link><pubDate>Tue, 02 Aug 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-104/</guid><description>LeetCode 104 解題筆記：深度等於 1 加上左右子樹深度的較大值；空樹是 0</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-104/featured.png"/></item><item><title>LeetCode 144: Binary Tree Preorder Traversal</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-144/</link><pubDate>Wed, 20 Jul 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-144/</guid><description>LeetCode 144 解題筆記：迭代的前序遍歷，彈出就記錄，先推右小孩再推左小孩，左邊才會先處理</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-144/featured.png"/></item><item><title>LeetCode 94: Binary Tree Inorder Traversal</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-94/</link><pubDate>Wed, 20 Jul 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-94/</guid><description>LeetCode 94 解題筆記：迭代的中序遍歷，一路往左把節點推進 stack，彈出時記錄，再轉向右子樹</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-94/featured.png"/></item></channel></rss>