原文链接: https://leetcode-cn.com/problems/longest-consecutive-sequence 英文原文Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence. You must write an algorithm that runs in O(n) time. Example 1: Input: nu…
标签详情
并查集 分类
原文链接: 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/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/evaluate-division 英文原文You are given an array of variable pairs equations and an array of real numbers values, where equations[i] = [Ai, Bi] and values[i] represent the equation Ai / Bi = values[i]. Each Ai or Bi…
原文链接: https://leetcode-cn.com/problems/number-of-provinces 英文原文There are n cities. Some of them are connected, while some are not. If city a is connected directly with city b, and city b is connected directly with city c, then city a is connected ind…
原文链接: 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/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/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/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/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/bricks-falling-when-hit 英文原文You are given an m x n binary grid, where each 1 represents a brick and 0 represents an empty space. A brick is stable if: It is directly connected to the top of the grid, or At least…
原文链接: 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/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/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/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/largest-component-size-by-common-factor 英文原文You are given an integer array of unique positive integers nums. Consider the following graph: There are nums.length nodes, labeled nums[0] to nums[nums.length - 1], T…
原文链接: 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/satisfiability-of-equality-equations 英文原文You are given an array of strings equations that represent relationships between variables where each string equations[i] is of length 4 and takes one of two different fo…
原文链接: 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/graph-connectivity-with-threshold 英文原文We have n cities labeled from 1 to n. Two different cities with labels x and y are directly connected by a bidirectional road if and only if x and y share a common divisor s…
原文链接: https://leetcode-cn.com/problems/rank-transform-of-a-matrix 英文原文Given an m x n matrix, return a new matrix answer where answer[row][col] is the rank of matrix[row][col]. The rank is an integer that represents how large an element is compared to…
原文链接: https://leetcode-cn.com/problems/validate-binary-tree-nodes 英文原文You have n binary tree nodes numbered from 0 to n - 1 where node i has two children leftChild[i] and rightChild[i], return true if and only if all the given nodes form exactly one …
原文链接: https://leetcode-cn.com/problems/smallest-string-with-swaps 英文原文You are given a string s, and an array of pairs of indices in the string pairs where pairs[i] = [a, b] indicates 2 indices(0-indexed) of the string. You can swap the characters at …
原文链接: https://leetcode-cn.com/problems/count-servers-that-communicate 英文原文You are given a map of a server center, represented as a m * n integer matrix grid, where 1 means that on that cell there is a server and 0 means that it is no server. Two serv…
原文链接: https://leetcode-cn.com/problems/number-of-operations-to-make-network-connected 英文原文There are n computers numbered from 0 to n-1 connected by ethernet cables connections forming a network where connections[i] = [a, b] represents a connection be…
原文链接: https://leetcode-cn.com/problems/check-if-there-is-a-valid-path-in-a-grid 英文原文Given a m x n grid. Each cell of the grid represents a street. The street of grid[i][j] can be: 1 which means a street connecting the left cell and the right cell. 2 …
1 / 2