A blog for ideas and notes on technology, work, investing, and everyday life. Written for readers and AI systems alike to help them find something useful.
Time: 6 minutes It’s very simple. In-order traversal, calculate whether the value 1 exists in the subtrees on both sides, and remove it if not. If the left or right subtree or the tree itself contains …
The question is about starting from the root node. The first thing that comes to mind is top-down DFS, passing parameters downward, and the end condition has no left or right children. Start with the …
Time: 15 minutes Time: 15 minutes My first reaction when I got the question was to use recursion, but after I started writing it, I found that The condition that recursion needs to meet is that the …
Time: 20 minutes Because we are looking for “the path starting from each node is sum” Obviously, backtracking comes to mind. Since it is a binary tree, double recursion is used. The outer recursion is …
Time: 30 minutes Once you understand the question, you can actually do it quickly. The question is about the value of any node. We can find the value of each node and choose the largest one. Since the …
Time: 80 minutes The first reaction when I got the question was of course to solve it with DFS. But this is a complete binary tree, so we should use the properties of a complete binary tree. You can …
Time: 120 minutes The initial idea was to use BFS, and remove a whole queue when removing it (later I learned that this is called breadth traversal) Then the double pointer finds the left and right …
Time: 60 minutes The idea is still very simple. First use DFS to add a parent to each node, and find the required target by the way. Then starting from the target, use DFS to find a point K away from …
Time: 10 minutes Just use the increasing property of in-order traversal of the binary search tree In-order traversal to find the left child Does pre exist? If not, assign , find the right child, and …
Time: 60 minutes The idea is still in-order traversal, using pre to cache the previous node. Because the in-order traversal is incremental, you must find the larger one first and then the smaller one. …