<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Binary-Tree on</title><link>https://h30306.github.io/blog/zh-tw/tags/binary-tree/</link><description>Recent content in Binary-Tree 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/binary-tree/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 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 889: Construct Binary Tree from Preorder and Postorder Traversal</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-889/</link><pubDate>Thu, 29 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-889/</guid><description>LeetCode 889 解題筆記：stack 存目前這條路徑，堆頂等於 postorder 的下一個就代表子樹完成要 pop；新節點先接左邊</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-889/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 331: Verify Preorder Serialization of a Binary Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-331/</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-331/</guid><description>LeetCode 331 解題筆記：數空位：一開始 1 個，每個節點用掉 1 個，非空節點再多出 2 個；中途不能變負，最後要剛好 0</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-331/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 450: Delete Node in a BST</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-450/</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-450/</guid><description>LeetCode 450 解題筆記：找到節點後分三種情況：沒有小孩、一個小孩直接接上，兩個小孩用右子樹最小值替換再刪掉它</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-450/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 173: Binary Search Tree Iterator</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-173/</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-173/</guid><description>LeetCode 173 解題筆記：攤平成陣列很直接但用 O(n) 空間；follow-up 用 stack 存左側鏈，均攤 O(1)、空間 O(h)</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-173/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 701: Insert into a Binary Search Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-701/</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-701/</guid><description>LeetCode 701 解題筆記：沿著 BST 往下走到空位接上新節點；空樹要直接回傳新節點</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-701/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>Tree 樹的遍歷與常見技巧</title><link>https://h30306.github.io/blog/zh-tw/algorithm/tree/</link><pubDate>Tue, 20 Oct 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/algorithm/tree/</guid><description>DFS 回傳值、BFS 層序、BST 上下界、往上找 LCA、樹的直徑與剪葉子</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/algorithm/tree/featured.png"/></item><item><title>LeetCode 1028: Recover a Tree From Preorder Traversal</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-1028/</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-1028/</guid><description>LeetCode 1028 解題筆記：用 stack 維護從根到目前節點的路徑，stack 長度就是深度</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-1028/featured.png"/></item><item><title>LeetCode 987: Vertical Order Traversal of a Binary Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-987/</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-987/</guid><description>LeetCode 987 解題筆記：收集 (欄, 列, 值) 三元組，排序後依欄分組</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-987/featured.png"/></item><item><title>LeetCode 2509: Cycle Length Queries in a Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-2509/</link><pubDate>Fri, 11 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-2509/</guid><description>LeetCode 2509 解題筆記：完全二元樹的編號，parent 就是 v // 2，比較大的往上爬到 LCA</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-2509/featured.png"/></item><item><title>LeetCode 2196: Create Binary Tree From Descriptions</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-2196/</link><pubDate>Fri, 26 Jun 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-2196/</guid><description>LeetCode 2196 解題筆記：用 dict 存節點一次連好，根是唯一不是任何人子節點的值</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-2196/featured.png"/></item><item><title>LeetCode 1339: Maximum Product of Splitted Binary Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-1339/</link><pubDate>Fri, 09 Jan 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-1339/</guid><description>LeetCode 1339 解題筆記：先算總和，再枚舉每棵子樹的和，不要改到輸入</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-1339/featured.png"/></item><item><title>LeetCode 865: Smallest Subtree with all the Deepest Nodes</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-865/</link><pubDate>Fri, 09 Jan 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-865/</guid><description>LeetCode 865 解題筆記：BFS 找最後一層再一起往上爬，或一次 DFS 回傳 (深度, 節點)</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-865/featured.png"/></item><item><title>LeetCode 1161: Maximum Level Sum of a Binary Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-1161/</link><pubDate>Tue, 06 Jan 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-1161/</guid><description>LeetCode 1161 解題筆記：把 None 放進下一層會多出一層假的總和 0</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-1161/featured.png"/></item><item><title>LeetCode 2236: Root Equals Sum of Children</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-2236/</link><pubDate>Wed, 17 Dec 2025 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-2236/</guid><description>LeetCode 2236 解題筆記：暖身題，順便練 C++ 的指標存取</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-2236/featured.png"/></item><item><title>LeetCode 1008: Construct Binary Search Tree from Preorder Traversal</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-1008/</link><pubDate>Wed, 16 Jul 2025 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-1008/</guid><description>LeetCode 1008 解題筆記：切陣列遞迴 O(n^2)，帶上界遞迴 O(n)</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-1008/featured.png"/></item><item><title>LeetCode 958: Check Completeness of a Binary Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-958/</link><pubDate>Wed, 16 Jul 2025 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-958/</guid><description>LeetCode 958 解題筆記：完整性是整體性質，用 BFS 檢查第一個空位之後還有沒有節點</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-958/featured.png"/></item><item><title>LeetCode 103: Binary Tree Zigzag Level Order Traversal</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-103/</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-103/</guid><description>LeetCode 103 解題筆記：一般的層序遍歷，奇數層的結果反轉就是之字形</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-103/featured.png"/></item><item><title>LeetCode 107: Binary Tree Level Order Traversal II</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-107/</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-107/</guid><description>LeetCode 107 解題筆記：一般的層序遍歷，最後把結果反轉，就是由下往上</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-107/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 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 222: Count Complete Tree Nodes</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-222/</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-222/</guid><description>LeetCode 222 解題筆記：完全二元樹，左右兩邊的最左高度相同代表那一邊是滿的，直接用 2^h - 1；O(log² n)</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-222/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 102: Binary Tree Level Order Traversal</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-102/</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-102/</guid><description>LeetCode 102 解題筆記：BFS 一次處理一整層，用目前這層的節點產生下一層；空樹回傳空 list</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-102/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 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 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 700: Search in a Binary Search Tree</title><link>https://h30306.github.io/blog/zh-tw/leetcode/leetcode-700/</link><pubDate>Wed, 31 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-700/</guid><description>LeetCode 700 解題筆記：比目標大就往左、比目標小就往右，找到就回傳那個節點</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-700/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 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 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 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 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 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 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>