原文链接: https://leetcode-cn.com/problems/making-a-large-island 英文原文You are given an n x n binary matrix grid. You are allowed to change at most one 0 to be 1. Return the size of the largest island in grid after applying this operation. An island is a 4…
标签详情
深度优先搜索 分类
原文链接: 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/similar-string-groups 英文原文Two strings X and Y are similar if we can swap two letters (in different positions) of X, so that it equals Y. Also two strings X and Y are similar if they are equal. For example, "tars…
原文链接: https://leetcode-cn.com/problems/keys-and-rooms 英文原文There are n rooms labeled from 0 to n - 1 and all the rooms are locked except for room 0. Your goal is to visit all the rooms. However, you cannot enter a locked room without having its key. W…
原文链接: 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/loud-and-rich 英文原文There is a group of n people labeled from 0 to n - 1 where each person has a different amount of money and a different level of quietness. You are given an array richer where richer[i] = [ai, b…
原文链接: https://leetcode-cn.com/problems/possible-bipartition 英文原文We want to split a group of n people (labeled from 1 to n) into two groups of any size. Each person may dislike some other people, and they should not go into the same group. Given the i…
原文链接: 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/minimize-malware-spread 英文原文You are given a network of n nodes represented as an n x n adjacency matrix graph, where the ith node is directly connected to the jth node if graph[i][j] == 1. Some nodes initial are…
原文链接: https://leetcode-cn.com/problems/minimize-malware-spread-ii 英文原文You are given a network of n nodes represented as an n x n adjacency matrix graph, where the ith node is directly connected to the jth node if graph[i][j] == 1. Some nodes initial …
原文链接: https://leetcode-cn.com/problems/shortest-bridge 英文原文You are given an n x n binary matrix grid where 1 represents land and 0 represents water. An island is a 4-directionally connected group of 1's not connected to any other 1's. There are exact…
原文链接: 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/most-stones-removed-with-same-row-or-column 英文原文On a 2D plane, we place n stones at some integer coordinate points. Each coordinate point may have at most one stone. A stone can be removed if it shares either th…
原文链接: https://leetcode-cn.com/problems/regions-cut-by-slashes 英文原文An n x n grid is composed of 1 x 1 squares where each 1 x 1 square consists of a '/', '\', or blank space ' '. These characters divide the square into contiguous regions. Given the gri…
原文链接: 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/number-of-enclaves 英文原文You are given an m x n binary matrix grid, where 0 represents a sea cell and 1 represents a land cell. A move consists of walking from one land cell to another adjacent (4-directionally) l…
原文链接: 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…
原文链接: https://leetcode-cn.com/problems/coloring-a-border 英文原文You are given an m x n integer matrix grid, and three integers row, col, and color. Each value in the grid represents the color of the grid square at that location. Two squares belong to th…
原文链接: https://leetcode-cn.com/problems/escape-a-large-maze 英文原文There is a 1 million by 1 million grid on an XY-plane, and the coordinates of each grid square are (x, y). We start at the source = [sx, sy] square and want to reach the target = [tx, ty]…
原文链接: https://leetcode-cn.com/problems/binary-search-tree-to-greater-sum-tree 英文原文Given the root of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all ke…