<?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/tags/binary-tree/</link><description>Recent content in Binary-Tree on</description><generator>Hugo -- gohugo.io</generator><language>en</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/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/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/leetcode/leetcode-2385/</guid><description>LeetCode 2385 note: turn the tree into an undirected graph and BFS from start; the number of levels minus one is the answer</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/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/leetcode/leetcode-968/</guid><description>LeetCode 968 note: post-order greedy with three states per node: has a camera, covered, not covered; place a camera only when a child is uncovered, and add one if the root is left uncovered</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/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/leetcode/leetcode-889/</guid><description>LeetCode 889 note: keep the current path on a stack; when its top equals the next postorder value that subtree is complete and is popped; new nodes go left first</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/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/leetcode/leetcode-437/</guid><description>LeetCode 437 note: prefix sums on a tree with a hash map: look up prefix - target before adding the current prefix, and undo it when leaving the node</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/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/leetcode/leetcode-863/</guid><description>LeetCode 863 note: turn the tree into an undirected graph (adding edges to parents), then BFS k steps from target</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/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/leetcode/leetcode-652/</guid><description>LeetCode 652 note: encode every subtree in post-order and report it on its second occurrence; string keys are O(n^2) worst case, (val, left id, right id) ids make it 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/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/leetcode/leetcode-297/</guid><description>LeetCode 297 note: pre-order with null markers identifies the tree uniquely; deserialize by consuming tokens from an iterator</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/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/leetcode/leetcode-331/</guid><description>LeetCode 331 note: count open slots: start with 1, every node fills one, a non-null node opens two more; never go negative and end at exactly 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/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/leetcode/leetcode-449/</guid><description>LeetCode 449 note: for a BST, pre-order without null markers is enough; deserialize recursively with bounds in 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/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/leetcode/leetcode-450/</guid><description>LeetCode 450 note: once the node is found: with zero or one child, splice the child in; with two, copy the right subtree&amp;rsquo;s minimum and delete that node</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/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/leetcode/leetcode-99/</guid><description>LeetCode 99 note: find the inversions in the in-order sequence: the earlier node of the first inversion and the later node of the last one were swapped</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/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/leetcode/leetcode-124/</guid><description>LeetCode 124 note: DFS returns the best downward chain and updates the answer with left chain + node + right chain at every node; drop negative chains</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/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/leetcode/leetcode-1372/</guid><description>LeetCode 1372 note: each node returns two values, the longest zigzag starting left and starting right; going left extends the left child&amp;rsquo;s start-right value</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/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/leetcode/leetcode-173/</guid><description>LeetCode 173 note: flattening to an array is simple but uses O(n) space; the follow-up keeps the left spine on a stack for amortized O(1) and O(h) space</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/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/leetcode/leetcode-515/</guid><description>LeetCode 515 note: BFS level order, taking the maximum of each level; start from -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/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/leetcode/leetcode-687/</guid><description>LeetCode 687 note: DFS returns the longest same-value downward chain in edges, and each node updates the answer with left + right</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/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/leetcode/leetcode-701/</guid><description>LeetCode 701 note: walk down the BST to an empty spot and attach the new node; an empty tree must return the new node</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/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/leetcode/leetcode-314/</guid><description>LeetCode 314 note: BFS with a column index; BFS is what guarantees top-to-bottom within a column and left-to-right within a row</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 Traversal and Common Techniques</title><link>https://h30306.github.io/blog/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/algorithm/tree/</guid><description>DFS return values, BFS level order, BST bounds, climbing to the LCA, tree diameter, and leaf trimming</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/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/leetcode/leetcode-1028/</guid><description>LeetCode 1028 note: a stack holds the path from the root to the current node, so its length is the depth</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/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/leetcode/leetcode-987/</guid><description>LeetCode 987 note: collect (col, row, val) triples, sort them, and group by column</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/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/leetcode/leetcode-2509/</guid><description>LeetCode 2509 note: in heap numbering the parent is v // 2, so climb the larger node until both meet at the 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/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/leetcode/leetcode-2196/</guid><description>LeetCode 2196 note: keep nodes in a dict and link them in one pass; the root is the only value that is nobody&amp;rsquo;s child</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/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/leetcode/leetcode-1339/</guid><description>LeetCode 1339 note: compute the total, enumerate every subtree sum, and leave the input untouched</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/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/leetcode/leetcode-865/</guid><description>LeetCode 865 note: BFS to the last level and climb together, or one DFS returning (depth, node)</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/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/leetcode/leetcode-1161/</guid><description>LeetCode 1161 note: pushing None into the next level creates a fake level with sum 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/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/leetcode/leetcode-2236/</guid><description>LeetCode 2236 note: a warm-up, plus practice with C++ pointer access</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/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/leetcode/leetcode-1008/</guid><description>LeetCode 1008 note: splitting the array is O(n^2); recursing with an upper bound is 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/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/leetcode/leetcode-958/</guid><description>LeetCode 958 note: completeness is a global property, so check with BFS whether any node follows the first gap</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/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/leetcode/leetcode-103/</guid><description>LeetCode 103 note: a normal level-order traversal with every odd level reversed gives the zigzag</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/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/leetcode/leetcode-107/</guid><description>LeetCode 107 note: a normal level-order traversal reversed at the end gives bottom-up order</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/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/leetcode/leetcode-113/</guid><description>LeetCode 113 note: backtrack with the current path and store a copy at a leaf whose total matches; values can be negative, so no early pruning</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/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/leetcode/leetcode-117/</guid><description>LeetCode 117 note: connect next pointers level by level with BFS; for a non-perfect tree, looking only at the neighbour&amp;rsquo;s children breaks the chain</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/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/leetcode/leetcode-129/</guid><description>LeetCode 129 note: on the way down multiply the current number by 10 and add the node&amp;rsquo;s value, adding it to the total at a leaf</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/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/leetcode/leetcode-222/</guid><description>LeetCode 222 note: in a complete tree, equal leftmost depths on both sides mean one side is perfect, counted as 2^h - 1, for 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/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/leetcode/leetcode-2331/</guid><description>LeetCode 2331 note: leaves are 0 or 1 and internal nodes are 2 for OR and 3 for AND, evaluated in post-order</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/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/leetcode/leetcode-236/</guid><description>LeetCode 236 note: recursion returns whichever of p or q a subtree contains; finding something on both sides means they split here, so this node is the 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/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/leetcode/leetcode-1379/</guid><description>LeetCode 1379 note: walk both trees in lockstep; when the original reaches target, the clone&amp;rsquo;s node at the same position is the answer, comparing node identity</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/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/leetcode/leetcode-337/</guid><description>LeetCode 337 note: tree DP where each node returns the best (rob it, skip it) pair; not robbing alternate levels</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/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/leetcode/leetcode-102/</guid><description>LeetCode 102 note: BFS one whole level at a time, building the next level from the current one; an empty tree returns an empty 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/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/leetcode/leetcode-1448/</guid><description>LeetCode 1448 note: pass the path maximum down during DFS; a node is good when its value is at least that maximum</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/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/leetcode/leetcode-199/</guid><description>LeetCode 199 note: in a level-order traversal, each level&amp;rsquo;s rightmost node is what you see from the right</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/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/leetcode/leetcode-230/</guid><description>LeetCode 230 note: a BST&amp;rsquo;s in-order traversal is ascending, so stop an iterative in-order walk at the k-th node</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/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/leetcode/leetcode-98/</guid><description>LeetCode 98 note: every node has a valid range (low, high); going left the upper bound becomes the node and going right the lower bound does; comparing parent and child is not enough</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/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/leetcode/leetcode-1022/</guid><description>LeetCode 1022 note: on the way down double the current number and add the node&amp;rsquo;s bit, adding it to the total at a leaf</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/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/leetcode/leetcode-938/</guid><description>LeetCode 938 note: prune with the BST order, going only right below low and only left above high, adding nodes inside the range</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/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/leetcode/leetcode-965/</guid><description>LeetCode 965 note: every value must equal the root&amp;rsquo;s; compare values while recursing, not the booleans the recursion returns</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/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/leetcode/leetcode-993/</guid><description>LeetCode 993 note: cousins share a depth but not a parent; record x&amp;rsquo;s and y&amp;rsquo;s depth and parent during DFS and compare</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/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/leetcode/leetcode-872/</guid><description>LeetCode 872 note: collect leaves left to right with DFS; BFS collects level by level, which is not left-to-right order</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/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/leetcode/leetcode-700/</guid><description>LeetCode 700 note: go left when the node is larger, right when smaller, and return the node when found</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/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/leetcode/leetcode-637/</guid><description>LeetCode 637 note: level-order traversal, dividing each level&amp;rsquo;s sum by its count</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/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/leetcode/leetcode-671/</guid><description>LeetCode 671 note: the root is the minimum; the second minimum is the smallest value larger than the root, and only subtrees equal to the root need searching</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/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/leetcode/leetcode-606/</guid><description>LeetCode 606 note: output in pre-order, keeping an empty () when only the left subtree is missing, and omitting the right parentheses when it is empty</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/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/leetcode/leetcode-563/</guid><description>LeetCode 563 note: return subtree sums in post-order; each node&amp;rsquo;s tilt is the difference of its subtree sums, added to the answer</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/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/leetcode/leetcode-572/</guid><description>LeetCode 572 note: for every node of root, check whether its subtree equals subRoot; recurse with isSubtree, not by comparing only the children</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/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/leetcode/leetcode-501/</guid><description>LeetCode 501 note: a BST&amp;rsquo;s in-order is sorted, so equal values are contiguous; count the current run during in-order, resetting the answer on a new maximum and appending on a tie</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/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/leetcode/leetcode-543/</guid><description>LeetCode 543 note: the diameter may skip the root; return heights in post-order while updating the answer with left + right height at every node, counting edges</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/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/leetcode/leetcode-404/</guid><description>LeetCode 404 note: tell each child during DFS whether it is a left child, adding only left children that are leaves</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/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/leetcode/leetcode-235/</guid><description>LeetCode 235 note: go left when both p and q are smaller, right when both are larger; otherwise (split, or one is the node itself) this node is the 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/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/leetcode/leetcode-226/</guid><description>LeetCode 226 note: swap every node&amp;rsquo;s children, using a simultaneous assignment so the already-changed side is not reused</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/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/leetcode/leetcode-145/</guid><description>LeetCode 145 note: iterative post-order pushes a node back with a visited flag on its first pop, then the right and left children; record it on the second pop</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/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/leetcode/leetcode-110/</guid><description>LeetCode 110 note: every node&amp;rsquo;s subtree heights must differ by at most 1; return heights in post-order and propagate -1 once unbalanced</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/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/leetcode/leetcode-111/</guid><description>LeetCode 111 note: minimum depth must end at a leaf; with only one child, the empty side (depth 0) cannot count as the minimum</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/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/leetcode/leetcode-112/</guid><description>LeetCode 112 note: subtract each value from targetSum on the way down; it works if the remainder matches at a leaf</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/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/leetcode/leetcode-100/</guid><description>LeetCode 100 note: two empty trees are equal, one empty and one not differ, and otherwise compare values and recurse on both sides</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/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/leetcode/leetcode-101/</guid><description>LeetCode 101 note: the left and right subtrees must mirror each other, outer with outer and inner with inner; compare values, not node objects</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/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/leetcode/leetcode-104/</guid><description>LeetCode 104 note: depth is 1 plus the larger subtree depth, with 0 for an empty tree</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/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/leetcode/leetcode-144/</guid><description>LeetCode 144 note: iterative pre-order traversal records on pop and pushes the right child before the left so the left is handled first</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/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/leetcode/leetcode-94/</guid><description>LeetCode 94 note: iterative in-order traversal, pushing nodes while going left, recording on pop, then turning to the right subtree</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-94/featured.png"/></item></channel></rss>