<?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/tags/depth-first-search/</link><description>Recent content in Depth-First-Search 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/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/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 2858: Minimum Edge Reversals So Every Node Is Reachable</title><link>https://h30306.github.io/blog/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/leetcode/leetcode-2858/</guid><description>LeetCode 2858 note: rerooting DP: count the reversals needed with root 0, then moving the root to a child adds 1 if that edge pointed down and subtracts 1 if it pointed up</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/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/leetcode/leetcode-834/</guid><description>LeetCode 834 note: rerooting DP: compute subtree sizes and ans[0] with root 0, then push ans[child] = ans[parent] - size + (n - size) to every node</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/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 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 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 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 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 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>LeetCode 2973: Find Number of Coins to Place in Tree Nodes</title><link>https://h30306.github.io/blog/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/leetcode/leetcode-2973/</guid><description>LeetCode 2973 note: the max product of three is either the three largest or the two smallest times the largest, so each subtree returns only its 2 smallest and 3 largest values, merged in post-order</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/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/leetcode/leetcode-1373/</guid><description>LeetCode 1373 note: a post-order traversal returns (sum, min, max, is_bst); a node roots a BST when the left max &amp;lt; its value &amp;lt; the right min</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/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/leetcode/leetcode-988/</guid><description>LeetCode 988 note: DFS prepending each character so the string at a leaf already reads leaf to root, and keep the smallest</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/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 116: Populating Next Right Pointers in Each Node</title><link>https://h30306.github.io/blog/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/leetcode/leetcode-116/</guid><description>LeetCode 116 note: in a perfect binary tree, walk each level through the next pointers already set on the level above: left.next = right and right.next = next.left, with O(1) extra space</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/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 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 133: Clone Graph</title><link>https://h30306.github.io/blog/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/leetcode/leetcode-133/</guid><description>LeetCode 133 note: during DFS map each old node to its copy and return the existing copy when revisited, avoiding infinite recursion; an empty graph returns 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/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/leetcode/leetcode-417/</guid><description>LeetCode 417 note: walk inward from each ocean&amp;rsquo;s shore to cells no lower than the current one; cells reached from both oceans are the answer</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/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/leetcode/leetcode-695/</guid><description>LeetCode 695 note: DFS each unvisited 1 to measure its island and keep the maximum; cells are the integer 1, not a string</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/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 79: Word Search</title><link>https://h30306.github.io/blog/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/leetcode/leetcode-79/</guid><description>LeetCode 79 note: backtrack from every cell, matching the next character in four directions with visited cells marked temporarily and restored; prune early with character counts</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/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 897: Increasing Order Search Tree</title><link>https://h30306.github.io/blog/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/leetcode/leetcode-897/</guid><description>LeetCode 897 note: in-order traversal appending nodes to a right-only chain with left children cleared; keep the dummy separate from the moving tail</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/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 783: Minimum Distance Between BST Nodes</title><link>https://h30306.github.io/blog/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/leetcode/leetcode-783/</guid><description>LeetCode 783 note: a BST&amp;rsquo;s in-order is ascending, so the minimum difference is between in-order neighbors; remember the previous value and compare</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/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/leetcode/leetcode-733/</guid><description>LeetCode 733 note: DFS or BFS from the start, recoloring 4-directional cells that share the start&amp;rsquo;s original color; return immediately if the colors are equal</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/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 653: Two Sum IV - Input is a BST</title><link>https://h30306.github.io/blog/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/leetcode/leetcode-653/</guid><description>LeetCode 653 note: traverse while keeping a set of seen values; finding k - val in it means a pair exists</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/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 559: Maximum Depth of N-ary Tree</title><link>https://h30306.github.io/blog/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/leetcode/leetcode-559/</guid><description>LeetCode 559 note: depth is 1 plus the deepest child, or 1 with no children</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/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 589: N-ary Tree Preorder Traversal</title><link>https://h30306.github.io/blog/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/leetcode/leetcode-589/</guid><description>LeetCode 589 note: n-ary pre-order records the node then each child in order; flatten recursive results with extend, not by appending a 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/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/leetcode/leetcode-590/</guid><description>LeetCode 590 note: post-order is each child then the node; iteratively, run a root-then-children-right-to-left pre-order and reverse the whole result</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/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 530: Minimum Absolute Difference in BST</title><link>https://h30306.github.io/blog/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/leetcode/leetcode-530/</guid><description>LeetCode 530 note: a BST&amp;rsquo;s in-order is ascending, so the minimum difference is between in-order neighbors; remember the previous value and compare</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/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 463: Island Perimeter</title><link>https://h30306.github.io/blog/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/leetcode/leetcode-463/</guid><description>LeetCode 463 note: each land cell contributes 4 edges, minus 2 for each land neighbor above or to the left</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/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 257: Binary Tree Paths</title><link>https://h30306.github.io/blog/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/leetcode/leetcode-257/</guid><description>LeetCode 257 note: DFS carrying the path string down, adding the whole path at each leaf</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/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>