原文链接: 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/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/bulb-switcher-ii 英文原文There is a room with n bulbs labeled from 1 to n that all are turned on initially, and four buttons on the wall. Each of the four buttons has a different functionality where: Button 1: Flips…
原文链接: https://leetcode-cn.com/problems/redundant-connection 英文原文In this problem, a tree is an undirected graph that is connected and has no cycles. You are given a graph that started as a tree with n nodes labeled from 1 to n, with one additional edg…
原文链接: https://leetcode-cn.com/problems/redundant-connection-ii 英文原文In this problem, a rooted tree is a directed graph such that, there is exactly one node (the root) for which all other nodes are descendants of this node, plus every node has exactly …
原文链接: 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/employee-importance 英文原文You have a data structure of employee information, including the employee's unique ID, importance value, and direct subordinates' IDs. You are given an array of employees employees where:…
原文链接: https://leetcode-cn.com/problems/max-area-of-island 英文原文You are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are…
原文链接: https://leetcode-cn.com/problems/accounts-merge 英文原文Given a list of accounts where each element accounts[i] is a list of strings, where the first element accounts[i][0] is a name, and the rest of the elements are emails representing emails of t…
原文链接: https://leetcode-cn.com/problems/flood-fill 英文原文An image is represented by an m x n integer grid image where image[i][j] represents the pixel value of the image. You are also given three integers sr, sc, and newColor. You should perform a flood…
原文链接: https://leetcode-cn.com/problems/network-delay-time 英文原文You are given a network of n nodes, labeled from 1 to n. You are also given times, a list of travel times as directed edges times[i] = (ui, vi, wi), where ui is the source node, vi is the …
原文链接: https://leetcode-cn.com/problems/contain-virus 英文原文A virus is spreading rapidly, and your task is to quarantine the infected area by installing walls. The world is modeled as an m x n binary grid isInfected, where isInfected[i][j] == 0 represen…
原文链接: https://leetcode-cn.com/problems/cracking-the-safe 英文原文There is a safe protected by a password. The password is a sequence of n digits where each digit can be in the range [0, k - 1]. The safe has a peculiar way of checking the password. When y…
原文链接: https://leetcode-cn.com/problems/pyramid-transition-matrix 英文原文You are stacking blocks to form a pyramid. Each block has a color, which is represented by a single letter. Each row of blocks contains one less block than the row beneath it and is…
原文链接: https://leetcode-cn.com/problems/flatten-a-multilevel-doubly-linked-list 英文原文You are given a doubly linked list, which contains nodes that have a next pointer, a previous pointer, and an additional child pointer. This child pointer may or may n…
原文链接: https://leetcode-cn.com/problems/couples-holding-hands 英文原文There are n couples sitting in 2n seats arranged in a row and want to hold hands. The people and seats are represented by an integer array row where row[i] is the ID of the person sitti…
原文链接: 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/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/swim-in-rising-water 英文原文You are given an n x n integer matrix grid where each value grid[i][j] represents the elevation at that point (i, j). The rain starts to fall. At time t, the depth of the water everywher…
原文链接: 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/is-graph-bipartite 英文原文There is an undirected graph with n nodes, where each node is numbered between 0 and n - 1. You are given a 2D array graph, where graph[u] is an array of nodes that node u is adjacent to. …
原文链接: https://leetcode-cn.com/problems/cheapest-flights-within-k-stops 英文原文There are n cities connected by some number of flights. You are given an array flights where flights[i] = [fromi, toi, pricei] indicates that there is a flight from city fromi…
原文链接: https://leetcode-cn.com/problems/all-paths-from-source-to-target 英文原文Given a directed acyclic graph (DAG) of n nodes labeled from 0 to n - 1, find all possible paths from node 0 to node n - 1 and return them in any order. The graph is given as …
原文链接: https://leetcode-cn.com/problems/find-eventual-safe-states 英文原文There is a directed graph of n nodes with each node labeled from 0 to n - 1. The graph is represented by a 0-indexed 2D integer array graph where graph[i] is an integer array of nod…
原文链接: 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…