原文链接: 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/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/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/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/surrounded-regions 英文原文Given an m x n matrix board containing 'X' and 'O', capture all regions that are 4-directionally surrounded by 'X'. A region is captured by flipping all 'O's into 'X's in that surrounded r…
原文链接: https://leetcode-cn.com/problems/clone-graph 英文原文Given a reference of a node in a connected undirected graph. Return a deep copy (clone) of the graph. Each node in the graph contains a value (int) and a list (List[Node]) of its neighbors. class…
原文链接: 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-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/number-of-islands 英文原文Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands. An island is surrounded by water and is formed by connecting adjacen…
原文链接: https://leetcode-cn.com/problems/course-schedule 英文原文There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take…
原文链接: https://leetcode-cn.com/problems/course-schedule-ii 英文原文There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must t…
原文链接: https://leetcode-cn.com/problems/design-add-and-search-words-data-structure 英文原文Design a data structure that supports adding new words and finding if a string matches any previously added string. Implement the WordDictionary class: WordDictiona…
原文链接: 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…
原文链接: 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 …
1 / 8