原文链接: 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/bus-routes 英文原文You are given an array routes representing bus routes where routes[i] is a bus route that the ith bus repeats forever. For example, if routes[0] = [1, 5, 7], this means that the 0th bus travels in…
原文链接: 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/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/shortest-path-visiting-all-nodes 英文原文You have an undirected, connected graph of n nodes labeled from 0 to n - 1. You are given an array graph where graph[i] is a list of all the nodes connected with node i by an…
原文链接: https://leetcode-cn.com/problems/k-similar-strings 英文原文Strings s1 and s2 are k-similar (for some non-negative integer k) if we can swap the positions of two letters in s1 exactly k times so that the resulting string equals s2. Given two anagram…
原文链接: 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/shortest-path-to-get-all-keys 英文原文You are given an m x n grid grid where: '.' is an empty cell. '#' is a wall. '@' is the starting point. Lowercase letters represent keys. Uppercase letters represent locks. You …
原文链接: 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/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/snakes-and-ladders 英文原文You are given an n x n integer matrix board where the cells are labeled from 1 to n2 in a Boustrophedon style starting from the bottom left of the board (i.e. board[n - 1][0]) and alternat…
原文链接: https://leetcode-cn.com/problems/cat-and-mouse 英文原文A game on an undirected graph is played by two players, Mouse and Cat, who alternate turns. The graph is given as follows: graph[a] is a list of all nodes b such that ab is an edge of the graph…
原文链接: https://leetcode-cn.com/problems/complete-binary-tree-inserter 英文原文A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible. Design an algorithm to i…
原文链接: 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/check-completeness-of-a-binary-tree 英文原文Given the root of a binary tree, determine if it is a complete binary tree. In a complete binary tree, every level, except possibly the last, is completely filled, and all…
原文链接: 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/numbers-with-same-consecutive-differences 英文原文Return all non-negative integers of length n such that the absolute difference between every two consecutive digits is k. Note that every number in the answer must n…
原文链接: 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/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/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/maximum-level-sum-of-a-binary-tree 英文原文Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on. Return the smallest level x such that the sum of all the values of n…