原文链接: https://leetcode-cn.com/problems/binary-tree-inorder-traversal 英文原文Given the root of a binary tree, return the inorder traversal of its nodes' values. Example 1: Input: root = [1,null,2,3] Output: [1,3,2] Example 2: Input: root = [] Output: [] …
标签详情
树 分类
原文链接: https://leetcode-cn.com/problems/unique-binary-search-trees-ii 英文原文Given an integer n, return all the structurally unique BST's (binary search trees), which has exactly n nodes of unique values from 1 to n. Return the answer in any order. Examp…
原文链接: https://leetcode-cn.com/problems/unique-binary-search-trees 英文原文Given an integer n, return the number of structurally unique BST's (binary search trees) which has exactly n nodes of unique values from 1 to n. Example 1: Input: n = 3 Output: 5 E…
原文链接: https://leetcode-cn.com/problems/validate-binary-search-tree 英文原文Given the root of a binary tree, determine if it is a valid binary search tree (BST). A valid BST is defined as follows: The left subtree of a node contains only nodes with keys l…
原文链接: https://leetcode-cn.com/problems/recover-binary-search-tree 英文原文You are given the root of a binary search tree (BST), where the values of exactly two nodes of the tree were swapped by mistake. Recover the tree without changing its structure. Ex…
原文链接: https://leetcode-cn.com/problems/same-tree 英文原文Given the roots of two binary trees p and q, write a function to check if they are the same or not. Two binary trees are considered the same if they are structurally identical, and the nodes have t…
原文链接: https://leetcode-cn.com/problems/symmetric-tree 英文原文Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center). Example 1: Input: root = [1,2,2,3,4,4,3] Output: true Example 2: Input: root = [1,2…
原文链接: https://leetcode-cn.com/problems/binary-tree-level-order-traversal 英文原文Given the root of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level). Example 1: Input: root = [3,9,20,null,nul…
原文链接: https://leetcode-cn.com/problems/maximum-depth-of-binary-tree 英文原文Given the root of a binary tree, return its maximum depth. A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest lea…
原文链接: https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal 英文原文Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder traversal of the s…
原文链接: https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal 英文原文Given two integer arrays inorder and postorder where inorder is the inorder traversal of a binary tree and postorder is the postorder traversal of t…
原文链接: https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii 英文原文Given the root of a binary tree, return the bottom-up level order traversal of its nodes' values. (i.e., from left to right, level by level from leaf to root). Example 1:…
原文链接: https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree 英文原文Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree. A height-balanced binary tree is a…
原文链接: https://leetcode-cn.com/problems/convert-sorted-list-to-binary-search-tree 英文原文Given the head of a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced binary …
原文链接: https://leetcode-cn.com/problems/balanced-binary-tree 英文原文Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as: a binary tree in which the left and right subtrees of every node d…
原文链接: https://leetcode-cn.com/problems/minimum-depth-of-binary-tree 英文原文Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. Note: A leaf is a …
原文链接: https://leetcode-cn.com/problems/path-sum 英文原文Given the root of a binary tree and an integer targetSum, return true if the tree has a root-to-leaf path such that adding up all the values along the path equals targetSum. A leaf is a node with no…
原文链接: https://leetcode-cn.com/problems/path-sum-ii 英文原文Given the root of a binary tree and an integer targetSum, return all root-to-leaf paths where the sum of the node values in the path equals targetSum. Each path should be returned as a list of th…
原文链接: https://leetcode-cn.com/problems/populating-next-right-pointers-in-each-node 英文原文You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following definition: struct…
原文链接: https://leetcode-cn.com/problems/populating-next-right-pointers-in-each-node-ii 英文原文Given a binary tree struct Node { int val; Node *left; Node *right; Node *next; } Populate each next pointer to point to its next right node. If there is no nex…
原文链接: https://leetcode-cn.com/problems/binary-tree-maximum-path-sum 英文原文A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence at most once.…
原文链接: https://leetcode-cn.com/problems/sum-root-to-leaf-numbers 英文原文You are given the root of a binary tree containing digits from 0 to 9 only. Each root-to-leaf path in the tree represents a number. For example, the root-to-leaf path 1 -> 2 -> 3 rep…
原文链接: https://leetcode-cn.com/problems/flatten-binary-tree-to-linked-list 英文原文Given the root of a binary tree, flatten the tree into a "linked list": The "linked list" should use the same TreeNode class where the right child pointer points to the nex…
原文链接: https://leetcode-cn.com/problems/binary-tree-preorder-traversal 英文原文Given the root of a binary tree, return the preorder traversal of its nodes' values. Example 1: Input: root = [1,null,2,3] Output: [1,2,3] Example 2: Input: root = [] Output: […
原文链接: https://leetcode-cn.com/problems/binary-tree-postorder-traversal 英文原文Given the root of a binary tree, return the postorder traversal of its nodes' values. Example 1: Input: root = [1,null,2,3] Output: [3,2,1] Example 2: Input: root = [] Output:…
原文链接: https://leetcode-cn.com/problems/binary-search-tree-iterator 英文原文Implement the BSTIterator class that represents an iterator over the in-order traversal of a binary search tree (BST): BSTIterator(TreeNode root) Initializes an object of the BSTI…
原文链接: https://leetcode-cn.com/problems/binary-tree-right-side-view 英文原文Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. Example 1: Input: root =…
原文链接: https://leetcode-cn.com/problems/count-complete-tree-nodes 英文原文Given the root of a complete binary tree, return the number of the nodes in the tree. According to Wikipedia, every level, except possibly the last, is completely filled in a comple…
原文链接: https://leetcode-cn.com/problems/invert-binary-tree 英文原文Given the root of a binary tree, invert the tree, and return its root. Example 1: Input: root = [4,2,7,1,3,6,9] Output: [4,7,2,9,6,3,1] Example 2: Input: root = [2,1,3] Output: [2,3,1] Exa…
原文链接: https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst 英文原文Given the root of a binary search tree, and an integer k, return the kth smallest value (1-indexed) of all the values of the nodes in the tree. Example 1: Input: root = [3,1,4,n…
1 / 6