原文链接: https://leetcode-cn.com/problems/maximum-depth-of-n-ary-tree 英文原文Given a n-ary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. Nary-Tree input seri…
标签详情
树 分类
原文链接: https://leetcode-cn.com/problems/logical-or-of-two-binary-grids-represented-as-quad-trees 英文原文A Binary Matrix is a matrix in which all the elements are either 0 or 1. Given quadTree1 and quadTree2. quadTree1 represents a n * n binary matrix and…
原文链接: https://leetcode-cn.com/problems/n-ary-tree-postorder-traversal 英文原文Given the root of an n-ary tree, return the postorder traversal of its nodes' values. Nary-Tree input serialization is represented in their level order traversal. Each group of…
原文链接: https://leetcode-cn.com/problems/search-in-a-binary-search-tree 英文原文You are given the root of a binary search tree (BST) and an integer val. Find the node in the BST that the node's value equals val and return the subtree rooted with that node.…
原文链接: https://leetcode-cn.com/problems/insert-into-a-binary-search-tree 英文原文You are given the root node of a binary search tree (BST) and a value to insert into the tree. Return the root node of the BST after the insertion. It is guaranteed that the …
原文链接: https://leetcode-cn.com/problems/kth-largest-element-in-a-stream 英文原文Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element. Implement KthLargest cla…
原文链接: https://leetcode-cn.com/problems/minimum-distance-between-bst-nodes 英文原文Given the root of a Binary Search Tree (BST), return the minimum difference between the values of any two different nodes in the tree. Example 1: Input: root = [4,2,6,1,3] …
原文链接: https://leetcode-cn.com/problems/binary-tree-pruning 英文原文Given the root of a binary tree, return the same tree where every subtree (of the given tree) not containing a 1 has been removed. A subtree of a node node is node plus every node that is…
原文链接: https://leetcode-cn.com/problems/sum-of-distances-in-tree 英文原文There is an undirected connected tree with n nodes labeled from 0 to n - 1 and n - 1 edges. You are given the integer n and the array edges where edges[i] = [ai, bi] indicates that t…
原文链接: https://leetcode-cn.com/problems/all-nodes-distance-k-in-binary-tree 英文原文Given the root of a binary tree, the value of a target node target, and an integer k, return an array of the values of all nodes that have a distance k from the target nod…
原文链接: https://leetcode-cn.com/problems/smallest-subtree-with-all-the-deepest-nodes 英文原文Given the root of a binary tree, the depth of each node is the shortest distance to the root. Return the smallest subtree such that it contains all the deepest nod…
原文链接: https://leetcode-cn.com/problems/leaf-similar-trees 英文原文Consider all the leaves of a binary tree, from left to right order, the values of those leaves form a leaf value sequence. For example, in the given tree above, the leaf value sequence is …
原文链接: https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal 英文原文Given two integer arrays, preorder and postorder where preorder is the preorder traversal of a binary tree of distinct values and postorder is the …
原文链接: https://leetcode-cn.com/problems/all-possible-full-binary-trees 英文原文Given an integer n, return a list of all possible full binary trees with n nodes. Each node of each tree in the answer must have Node.val == 0. Each element of the answer is th…
原文链接: https://leetcode-cn.com/problems/increasing-order-search-tree 英文原文Given the root of a binary search tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and onl…
原文链接: https://leetcode-cn.com/problems/complete-binary-tree-inserter 英文原文A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible. Design an algorithm to i…
原文链接: https://leetcode-cn.com/problems/range-sum-of-bst 英文原文Given the root node of a binary search tree and two integers low and high, return the sum of values of all nodes with a value in the inclusive range [low, high]. Example 1: Input: root = [10…
原文链接: https://leetcode-cn.com/problems/check-completeness-of-a-binary-tree 英文原文Given the root of a binary tree, determine if it is a complete binary tree. In a complete binary tree, every level, except possibly the last, is completely filled, and all…
原文链接: https://leetcode-cn.com/problems/univalued-binary-tree 英文原文A binary tree is uni-valued if every node in the tree has the same value. Given the root of a binary tree, return true if the given tree is uni-valued, or false otherwise. Example 1: In…
原文链接: https://leetcode-cn.com/problems/binary-tree-cameras 英文原文You are given the root of a binary tree. We install cameras on the tree nodes where each camera at a node can monitor its parent, itself, and its immediate children. Return the minimum nu…
原文链接: https://leetcode-cn.com/problems/flip-binary-tree-to-match-preorder-traversal 英文原文You are given the root of a binary tree with n nodes, where each node is uniquely assigned a value from 1 to n. You are also given a sequence of n values voyage, …
原文链接: https://leetcode-cn.com/problems/distribute-coins-in-binary-tree 英文原文You are given the root of a binary tree with n nodes where each node in the tree has node.val coins. There are n coins in total throughout the whole tree. In one move, we may …
原文链接: https://leetcode-cn.com/problems/vertical-order-traversal-of-a-binary-tree 英文原文Given the root of a binary tree, calculate the vertical order traversal of the binary tree. For each node at position (row, col), its left and right children will be…
原文链接: https://leetcode-cn.com/problems/smallest-string-starting-from-leaf 英文原文You are given the root of a binary tree where each node has a value in the range [0, 25] representing the letters 'a' to 'z'. Return the lexicographically smallest string t…
原文链接: https://leetcode-cn.com/problems/cousins-in-binary-tree 英文原文Given the root of a binary tree with unique values and the values of two different nodes of the tree x and y, return true if the nodes corresponding to the values x and y in the tree a…
原文链接: https://leetcode-cn.com/problems/maximum-binary-tree-ii 英文原文A maximum tree is a tree where every node has a value greater than any other value in its subtree. You are given the root of a maximum binary tree and an integer val. Just as in the pr…
原文链接: https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal 英文原文Given an array of integers preorder, which represents the preorder traversal of a BST (i.e., binary search tree), construct the tree and return its root. …
原文链接: https://leetcode-cn.com/problems/sum-of-root-to-leaf-binary-numbers 英文原文You are given the root of a binary tree where each node has a value 0 or 1. Each root-to-leaf path represents a binary number starting with the most significant bit. For ex…
原文链接: https://leetcode-cn.com/problems/maximum-difference-between-node-and-ancestor 英文原文Given the root of a binary tree, find the maximum value v for which there exist different nodes a and b where v = |a.val - b.val| and a is an ancestor of b. A nod…
原文链接: https://leetcode-cn.com/problems/recover-a-tree-from-preorder-traversal 英文原文We run a preorder depth-first search (DFS) on the root of a binary tree. At each node in this traversal, we output D dashes (where D is the depth of this node), then we…