原文链接: https://leetcode-cn.com/problems/sum-of-nodes-with-even-valued-grandparent 英文原文Given the root of a binary tree, return the sum of values of nodes with an even-valued grandparent. If there are no nodes with an even-valued grandparent, return 0. …
标签详情
二叉树 分类
原文链接: https://leetcode-cn.com/problems/binary-tree-coloring-game 英文原文Two players play a turn based game on a binary tree. We are given the root of this binary tree, and the number of nodes n in the tree. n is odd, and each node has a distinct value f…
原文链接: https://leetcode-cn.com/problems/deepest-leaves-sum 英文原文Given the root of a binary tree, return the sum of values of its deepest leaves. Example 1: Input: root = [1,2,3,4,5,null,6,7,null,null,null,null,8] Output: 15 Example 2: Input: root = [6,…
原文链接: https://leetcode-cn.com/problems/validate-binary-tree-nodes 英文原文You have n binary tree nodes numbered from 0 to n - 1 where node i has two children leftChild[i] and rightChild[i], return true if and only if all the given nodes form exactly one …
原文链接: https://leetcode-cn.com/problems/balance-a-binary-search-tree 英文原文Given the root of a binary search tree, return a balanced binary search tree with the same node values. If there is more than one answer, return any of them. A binary search tree…
原文链接: https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree 英文原文Given a binary tree with the following rules: root.val == 0 If treeNode.val == x and treeNode.left != null, then treeNode.left.val == 2 * x + 1 If treeNode.val == …
原文链接: https://leetcode-cn.com/problems/all-elements-in-two-binary-search-trees 英文原文Given two binary search trees root1 and root2. Return a list containing all the integers from both trees sorted in ascending order. Example 1: Input: root1 = [2,1,4], …
原文链接: https://leetcode-cn.com/problems/maximum-product-of-splitted-binary-tree 英文原文Given the root of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized. Return th…
原文链接: https://leetcode-cn.com/problems/longest-zigzag-path-in-a-binary-tree 英文原文You are given the root of a binary tree. A ZigZag path for a binary tree is defined as follow: Choose any node in the binary tree and a direction (right or left). If the …
原文链接: https://leetcode-cn.com/problems/maximum-sum-bst-in-binary-tree 英文原文Given a binary tree root, return the maximum sum of all keys of any sub-tree which is also a Binary Search Tree (BST). Assume a BST is defined as follows: The left subtree of a…
原文链接: https://leetcode-cn.com/problems/linked-list-in-binary-tree 英文原文Given a binary tree root and a linked list with head as the first node. Return True if all the elements in the linked list starting from the head correspond to some downward path c…
原文链接: https://leetcode-cn.com/problems/find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree 英文原文Given two binary trees original and cloned and given a reference to a node target in the original tree. The cloned tree is a copy of the ori…
原文链接: https://leetcode-cn.com/problems/count-good-nodes-in-binary-tree 英文原文Given a binary tree root, a node X in the tree is named good if in the path from root to X there are no nodes with a value greater than X. Return the number of good nodes in t…
原文链接: https://leetcode-cn.com/problems/pseudo-palindromic-paths-in-a-binary-tree 英文原文Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be pseudo-palindromic if at least one permutation of the node valu…
原文链接: https://leetcode-cn.com/problems/number-of-good-leaf-nodes-pairs 英文原文Given the root of a binary tree and an integer distance. A pair of two different leaf nodes of a binary tree is said to be good if the length of the shortest path between them…
原文链接: https://leetcode-cn.com/problems/number-of-ways-to-reorder-array-to-get-same-bst 英文原文Given an array nums that represents a permutation of integers from 1 to n. We are going to construct a binary search tree (BST) by inserting the elements of nu…
原文链接: https://leetcode-cn.com/problems/even-odd-tree 英文原文A binary tree is named Even-Odd if it meets the following conditions: The root of the binary tree is at level index 0, its children are at level index 1, their children are at level index 2, et…
原文链接: https://leetcode-cn.com/problems/merge-bsts-to-create-single-bst 英文原文You are given n BST (binary search tree) root nodes for n separate BSTs stored in an array trees (0-indexed). Each BST in trees has at most 3 nodes, and no two roots have the …
原文链接: https://leetcode-cn.com/problems/count-nodes-with-the-highest-score 英文原文There is a binary tree rooted at 0 consisting of n nodes. The nodes are labeled from 0 to n - 1. You are given a 0-indexed integer array parents representing the tree, wher…
原文链接: https://leetcode-cn.com/problems/minimum-height-tree-lcci 英文原文Given a sorted (increasing order) array with unique integer elements, write an algo­rithm to create a binary search tree with minimal height. Example: Given sorted array: [-10,-3…
原文链接: https://leetcode-cn.com/problems/list-of-depth-lcci 英文原文Given a binary tree, design an algorithm which creates a linked list of all the nodes at each depth (e.g., if you have a tree with depth D, you'll have D linked lists). Return a array cont…
原文链接: https://leetcode-cn.com/problems/check-balance-lcci 英文原文Implement a function to check if a binary tree is balanced. For the purposes of this question, a balanced tree is defined to be a tree such that the heights of the two subtrees of any node…
原文链接: https://leetcode-cn.com/problems/legal-binary-search-tree-lcci 英文原文Implement a function to check if a binary tree is a binary search tree. Example 1: Input: 2 / \ 1 3 Output: true Example 2: Input: 5 / \ 1 4 / \ 3 6 Output: false Explanation: I…
原文链接: https://leetcode-cn.com/problems/successor-lcci 英文原文Write an algorithm to find the "next" node (i.e., in-order successor) of a given node in a binary search tree. Return null if there's no "next" node for the given node. Example 1: Input: root …
原文链接: https://leetcode-cn.com/problems/first-common-ancestor-lcci 英文原文Design an algorithm and write code to find the first common ancestor of two nodes in a binary tree. Avoid storing additional nodes in a data structure. NOTE: This is not necessaril…
原文链接: https://leetcode-cn.com/problems/check-subtree-lcci 英文原文T1 and T2 are two very large binary trees. Create an algorithm to determine if T2 is a subtree of T1. A tree T2 is a subtree of T1 if there exists a node n in T1 such that the subtree of n…
原文链接: https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof 中文题目输入某二叉树的前序遍历和中序遍历的结果,请构建该二叉树并返回其根节点。 假设输入的前序遍历和中序遍历的结果中都不含重复的数字。 示例 1: Input: preorder = [3,9,20,15,7], inorder = [9,3,15,20,7] Output: [3,9,20,null,null,15,7] 示例 2: Input: preorder…
原文链接: https://leetcode-cn.com/problems/shu-de-zi-jie-gou-lcof 中文题目输入两棵二叉树A和B,判断B是不是A的子结构。(约定空树不是任意一个树的子结构) B是A的子结构, 即 A中有出现和B相同的结构和节点值。 例如: 给定的树 A: 3 / \ 4 5 / \ 1 2 给定的树 B: 4 / 1 返回 true,因为 B 与 A 的一个子树拥有相同的结构和节点值。 示例 1: 输入:A = [1,2,3], B = [3,1] 输出:…
原文链接: https://leetcode-cn.com/problems/er-cha-shu-de-jing-xiang-lcof 中文题目请完成一个函数,输入一个二叉树,该函数输出它的镜像。 例如输入: 4 / \ 2 7 / \ / \ 1 3 6 9 镜像输出: 4 / \ 7 2 / \ / \ 9 6 3 1 示例 1: 输入:root = [4,2,7,1,3,6,9] 输出:[4,7,2,9,6,3,1] 限制: 0 <= 节点个数 <= 1000 注意:本题与主站 226 …
原文链接: https://leetcode-cn.com/problems/dui-cheng-de-er-cha-shu-lcof 中文题目请实现一个函数,用来判断一棵二叉树是不是对称的。如果一棵二叉树和它的镜像一样,那么它是对称的。 例如,二叉树 [1,2,2,3,4,4,3] 是对称的。 1 / \ 2 2 / \ / \ 3 4 4 3 但是下面这个 [1,2,2,null,3,null,3] 则不是镜像对称的: 1 / \ 2 2 \ \ 3 3 示例 1: 输入:root = [1…