原文链接: https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree 英文原文Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. According to the definition of LCA on Wikipedia: “T…
标签详情
树 分类
原文链接: https://leetcode-cn.com/problems/binary-tree-paths 英文原文Given the root of a binary tree, return all root-to-leaf paths in any order. A leaf is a node with no children. Example 1: Input: root = [1,2,3,null,5] Output: ["1->2->5","1->3"] Example 2:…
原文链接: https://leetcode-cn.com/problems/serialize-and-deserialize-binary-tree 英文原文Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across …
原文链接: https://leetcode-cn.com/problems/verify-preorder-serialization-of-a-binary-tree 英文原文One way to serialize a binary tree is to use preorder traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record …
原文链接: https://leetcode-cn.com/problems/house-robber-iii 英文原文The thief has found himself a new place for his thievery again. There is only one entrance to this area, called root. Besides the root, each house has one and only one parent house. After a …
原文链接: https://leetcode-cn.com/problems/flatten-nested-list-iterator 英文原文You are given a nested list of integers nestedList. Each element is either an integer or a list whose elements may also be integers or other lists. Implement an iterator to flatt…
原文链接: https://leetcode-cn.com/problems/sum-of-left-leaves 英文原文Given the root of a binary tree, return the sum of all left leaves. Example 1: Input: root = [3,9,20,null,null,15,7] Output: 24 Explanation: There are two left leaves in the binary tree, w…
原文链接: https://leetcode-cn.com/problems/path-sum-iii 英文原文Given the root of a binary tree and an integer targetSum, return the number of paths where the sum of the values along the path equals targetSum. The path does not need to start or end at the ro…
原文链接: https://leetcode-cn.com/problems/serialize-and-deserialize-bst 英文原文Serialization is converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection li…
原文链接: https://leetcode-cn.com/problems/delete-node-in-a-bst 英文原文Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST. Basically, the deletion can b…
原文链接: https://leetcode-cn.com/problems/find-mode-in-binary-search-tree 英文原文Given the root of a binary search tree (BST) with duplicates, return all the mode(s) (i.e., the most frequently occurred element) in it. If the tree has more than one mode, re…
原文链接: https://leetcode-cn.com/problems/most-frequent-subtree-sum 英文原文Given the root of a binary tree, return the most frequent subtree sum. If there is a tie, return all the values with the highest frequency in any order. The subtree sum of a node is…
原文链接: https://leetcode-cn.com/problems/find-bottom-left-tree-value 英文原文Given the root of a binary tree, return the leftmost value in the last row of the tree. Example 1: Input: root = [2,1,3] Output: 1 Example 2: Input: root = [1,2,3,4,null,5,6,null,…
原文链接: https://leetcode-cn.com/problems/find-largest-value-in-each-tree-row 英文原文Given the root of a binary tree, return an array of the largest value in each row of the tree (0-indexed). Example 1: Input: root = [1,3,2,5,3,null,9] Output: [1,3,9] Exam…
原文链接: https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst 英文原文Given the root of a Binary Search Tree (BST), return the minimum absolute difference between the values of any two different nodes in the tree. Example 1: Input: root = [4,…
原文链接: https://leetcode-cn.com/problems/convert-bst-to-greater-tree 英文原文Given the root of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater …
原文链接: https://leetcode-cn.com/problems/diameter-of-binary-tree 英文原文Given the root of a binary tree, return the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This p…
原文链接: https://leetcode-cn.com/problems/binary-tree-tilt 英文原文Given the root of a binary tree, return the sum of every tree node's tilt. The tilt of a tree node is the absolute difference between the sum of all left subtree node values and all right su…
原文链接: https://leetcode-cn.com/problems/subtree-of-another-tree 英文原文Given the roots of two binary trees root and subRoot, return true if there is a subtree of root with the same structure and node values of subRoot and false otherwise. A subtree of a …
原文链接: https://leetcode-cn.com/problems/construct-string-from-binary-tree 英文原文Given the root of a binary tree, construct a string consisting of parenthesis and integers from a binary tree with the preorder traversal way, and return it. Omit all the em…
原文链接: https://leetcode-cn.com/problems/merge-two-binary-trees 英文原文You are given two binary trees root1 and root2. Imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not. You need …
原文链接: https://leetcode-cn.com/problems/add-one-row-to-tree 英文原文Given the root of a binary tree and two integers val and depth, add a row of nodes with value val at the given depth depth. Note that the root node is at depth 1. The adding rule is: Give…
原文链接: https://leetcode-cn.com/problems/find-duplicate-subtrees 英文原文Given the root of a binary tree, return all duplicate subtrees. For each kind of duplicate subtrees, you only need to return the root node of any one of them. Two trees are duplicate …
原文链接: https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst 英文原文Given the root of a Binary Search Tree and a target number k, return true if there exist two elements in the BST such that their sum is equal to the given target. Example 1: Input: …
原文链接: https://leetcode-cn.com/problems/maximum-binary-tree 英文原文You are given an integer array nums with no duplicates. A maximum binary tree can be built recursively from nums using the following algorithm: Create a root node whose value is the maxim…
原文链接: https://leetcode-cn.com/problems/print-binary-tree 英文原文Given the root of a binary tree, construct a 0-indexed m x n string matrix res that represents a formatted layout of the tree. The formatted layout matrix should be constructed using the fo…
原文链接: https://leetcode-cn.com/problems/maximum-width-of-binary-tree 英文原文Given the root of a binary tree, return the maximum width of the given tree. The maximum width of a tree is the maximum width among all levels. The width of one level is defined …
原文链接: https://leetcode-cn.com/problems/trim-a-binary-search-tree 英文原文Given the root of a binary search tree and the lowest and highest boundaries as low and high, trim the tree so that all its elements lies in [low, high]. Trimming the tree should no…
原文链接: https://leetcode-cn.com/problems/longest-univalue-path 英文原文Given the root of a binary tree, return the length of the longest path, where each node in the path has the same value. This path may or may not pass through the root. The length of the…
原文链接: https://leetcode-cn.com/problems/construct-quad-tree 英文原文Given a n * n matrix grid of 0's and 1's only. We want to represent the grid with a Quad-Tree. Return the root of the Quad-Tree representing the grid. Notice that you can assign the value…