leetcode.cn 2023-06-22
🟡面试题 16.19.pond-sizes-lcci
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #array #matrix
🟡面试题 16.19.pond-sizes-lcci
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #array #matrix
Telegraph
pond-sizes-lcci
你有一个用于表示一片土地的整数矩阵land,该矩阵中每个点的值代表对应地点的海拔高度。若值为0则表示水域。由垂直、水平或对角连接的水域为池塘。池塘的大小是指相连接的水域的个数。编写一个方法来计算矩阵中所有池塘的大小,返回值需要从小到大排序。 示例: 输入: [ [0,2,1,0], [0,1,0,1], [1,1,0,1], [0,1,0,1] ] 输出: [1,2,4] 提示: 0 < len(land) <= 1000 0 < len(land[i]) <= 1000
leetcode.com 2023-06-30
🔴1970.last-day-where-you-can-still-cross
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #array #binary_search #matrix
🔴1970.last-day-where-you-can-still-cross
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #array #binary_search #matrix
Telegraph
last-day-where-you-can-still-cross
There is a 1-based binary matrix where 0 represents land and 1 represents water. You are given integers row and col representing the number of rows and columns in the matrix, respectively. Initially on day 0, the entire matrix is land. However, each day a…
leetcode.com 2023-08-19
🔴1489.find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree
🏷️ Tags
#union_find #graph #minimum_spanning_tree #sorting #strongly_connected_component
🔴1489.find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree
🏷️ Tags
#union_find #graph #minimum_spanning_tree #sorting #strongly_connected_component
Telegraph
find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree
Given a weighted undirected connected graph with n vertices numbered from 0 to n - 1, and an array edges where edges[i] = [ai, bi, weighti] represents a bidirectional and weighted edge between nodes ai and bi. A minimum spanning tree (MST) is a subset of…
leetcode.cn 2023-08-24
🟡1267.count-servers-that-communicate
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #array #counting #matrix
🟡1267.count-servers-that-communicate
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #array #counting #matrix
Telegraph
count-servers-that-communicate
这里有一幅服务器分布图,服务器的位置标识在 m * n 的整数矩阵网格 grid 中,1 表示单元格上有服务器,0 表示没有。 如果两台服务器位于同一行或者同一列,我们就认为它们之间可以进行通信。 请你统计并返回能够与至少一台其他服务器进行通信的服务器的数量。 示例 1: 输入:grid = [[1,0],[0,1]] 输出:0 解释:没有一台服务器能与其他服务器进行通信。 示例 2: 输入:grid = [[1,0],[1,1]] 输出:3 解释:所有这些服务器都至少可以与一台别的服务器进行通信。…
leetcode.com 2023-09-15
🟡1584.min-cost-to-connect-all-points
🏷️ Tags
#union_find #graph #array #minimum_spanning_tree
🟡1584.min-cost-to-connect-all-points
🏷️ Tags
#union_find #graph #array #minimum_spanning_tree
Telegraph
min-cost-to-connect-all-points
You are given an array points representing integer coordinates of some points on a 2D-plane, where points[i] = [xi, yi]. The cost of connecting two points [xi, yi] and [xj, yj] is the manhattan distance between them: |xi - xj| + |yi - yj|, where |val| denotes…
leetcode.com 2023-09-16
🟡1631.path-with-minimum-effort
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #array #binary_search #matrix #heap_priority_queue
🟡1631.path-with-minimum-effort
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #array #binary_search #matrix #heap_priority_queue
Telegraph
path-with-minimum-effort
You are a hiker preparing for an upcoming hike. You are given heights, a 2D array of size rows x columns, where heights[row][col] represents the height of cell (row, col). You are situated in the top-left cell, (0, 0), and you hope to travel to the bottom…
leetcode.com 2023-10-17
🟡1361.validate-binary-tree-nodes
🏷️ Tags
#tree #depth_first_search #breadth_first_search #union_find #graph #binary_tree
🟡1361.validate-binary-tree-nodes
🏷️ Tags
#tree #depth_first_search #breadth_first_search #union_find #graph #binary_tree
Telegraph
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 valid binary tree. If node i has no left child then leftChild[i] will equal…
leetcode.cn 2023-10-21
🟡2316.count-unreachable-pairs-of-nodes-in-an-undirected-graph
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #graph
🟡2316.count-unreachable-pairs-of-nodes-in-an-undirected-graph
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #graph
Telegraph
count-unreachable-pairs-of-nodes-in-an-undirected-graph
给你一个整数 n ,表示一张 无向图 中有 n 个节点,编号为 0 到 n - 1 。同时给你一个二维整数数组 edges ,其中 edges[i] = [ai, bi] 表示节点 ai 和 bi 之间有一条 无向 边。 请你返回 无法互相到达 的不同 点对数目 。 示例 1: 输入:n = 3, edges = [[0,1],[0,2],[1,2]] 输出:0 解释:所有点都能互相到达,意味着没有点对无法互相到达,所以我们返回 0 。 示例 2: 输入:n = 7, edges = [[0,2],[0…
leetcode.cn 2023-10-31
🔴2003.smallest-missing-genetic-value-in-each-subtree
🏷️ Tags
#tree #depth_first_search #union_find #dynamic_programming
🔴2003.smallest-missing-genetic-value-in-each-subtree
🏷️ Tags
#tree #depth_first_search #union_find #dynamic_programming
Telegraph
smallest-missing-genetic-value-in-each-subtree
有一棵根节点为 0 的 家族树 ,总共包含 n 个节点,节点编号为 0 到 n - 1 。给你一个下标从 0 开始的整数数组 parents ,其中 parents[i] 是节点 i 的父节点。由于节点 0 是 根 ,所以 parents[0] == -1 。 总共有 105 个基因值,每个基因值都用 闭区间 [1, 105] 中的一个整数表示。给你一个下标从 0 开始的整数数组 nums ,其中 nums[i] 是节点 i 的基因值,且基因值 互不相同 。 请你返回一个数组 ans ,长度为 n ,其…
leetcode.cn 2023-11-11
🔴765.couples-holding-hands
🏷️ Tags
#greedy #depth_first_search #breadth_first_search #union_find #graph
🔴765.couples-holding-hands
🏷️ Tags
#greedy #depth_first_search #breadth_first_search #union_find #graph
Telegraph
couples-holding-hands
n 对情侣坐在连续排列的 2n 个座位上,想要牵到对方的手。 人和座位由一个整数数组 row 表示,其中 row[i] 是坐在第 i 个座位上的人的 ID。情侣们按顺序编号,第一对是 (0, 1),第二对是 (2, 3),以此类推,最后一对是 (2n-2, 2n-1)。 返回 最少交换座位的次数,以便每对情侣可以并肩坐在一起。 每次交换可选择任意两人,让他们站起来交换座位。 示例 1: 输入: row = [0,2,1,3] 输出: 1 解释: 只需要交换row[1]和row[2]的位置即可。 示例…
leetcode.cn 2023-12-11
🟡1631.path-with-minimum-effort
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #array #binary_search #matrix #heap_priority_queue
🟡1631.path-with-minimum-effort
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #array #binary_search #matrix #heap_priority_queue
Telegraph
path-with-minimum-effort
你准备参加一场远足活动。给你一个二维 rows x columns 的地图 heights ,其中 heights[row][col] 表示格子 (row, col) 的高度。一开始你在最左上角的格子 (0, 0) ,且你希望去最右下角的格子 (rows-1, columns-1) (注意下标从 0 开始编号)。你每次可以往 上,下,左,右 四个方向之一移动,你想要找到耗费 体力 最小的一条路径。 一条路径耗费的 体力值 是路径上相邻格子之间 高度差绝对值 的 最大值 决定的。 请你返回从左上角走到右下角的最小 体力消耗值 。…
leetcode.com 2025-03-20
🔴3108.minimum-cost-walk-in-weighted-graph
🏷️ Tags
#bit_manipulation #union_find #graph #array
🔴3108.minimum-cost-walk-in-weighted-graph
🏷️ Tags
#bit_manipulation #union_find #graph #array
Telegraph
minimum-cost-walk-in-weighted-graph
There is an undirected weighted graph with n vertices labeled from 0 to n - 1. You are given the integer n and an array edges, where edges[i] = [ui, vi, wi] indicates that there is an edge between vertices ui and vi with a weight of wi. A walk on a graph…
👍1
leetcode.com 2025-03-22
🟡2685.count-the-number-of-complete-components
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #graph
🟡2685.count-the-number-of-complete-components
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #graph
Telegraph
count-the-number-of-complete-components
You are given an integer n. There is an undirected graph with n vertices, numbered from 0 to n - 1. You are given a 2D integer array edges where edges[i] = [ai, bi] denotes that there exists an undirected edge connecting vertices ai and bi. Return the number…
leetcode.com 2025-03-28
🔴2503.maximum-number-of-points-from-grid-queries
🏷️ Tags
#breadth_first_search #union_find #array #two_pointers #matrix #sorting #heap_priority_queue
🔴2503.maximum-number-of-points-from-grid-queries
🏷️ Tags
#breadth_first_search #union_find #array #two_pointers #matrix #sorting #heap_priority_queue
Telegraph
maximum-number-of-points-from-grid-queries
You are given an m x n integer matrix grid and an array queries of size k. Find an array answer of size k such that for each integer queries[i] you start in the top left cell of the matrix and repeat the following process:
leetcode.cn 2025-10-06
🔴778.swim-in-rising-water
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #array #binary_search #matrix #heap_priority_queue
🔴778.swim-in-rising-water
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #array #binary_search #matrix #heap_priority_queue
Telegraph
swim-in-rising-water
在一个 n x n 的整数矩阵 grid 中,每一个方格的值 grid[i][j] 表示位置 (i, j) 的平台高度。 当开始下雨时,在时间为 t 时,水池中的水位为 t 。你可以从一个平台游向四周相邻的任意一个平台,但是前提是此时水位必须同时淹没这两个平台。假定你可以瞬间移动无限距离,也就是默认在方格内部游动是不耗时的。当然,在你游泳的时候你必须待在坐标方格里面。 你从坐标方格的左上平台 (0,0) 出发。返回 你到达坐标方格的右下平台 (n-1, n-1) 所需的最少时间 。 示例 1: 输入:…
leetcode.com 2025-10-06
🔴778.swim-in-rising-water
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #array #binary_search #matrix #heap_priority_queue
🔴778.swim-in-rising-water
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #array #binary_search #matrix #heap_priority_queue
Telegraph
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). It starts raining, and water gradually rises over time. At time t, the water level is t, meaning any cell with elevation less than equal…
leetcode.cn 2025-11-06
🟡3607.power-grid-maintenance
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #graph #array #hash_table #ordered_set #heap_priority_queue
🟡3607.power-grid-maintenance
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #graph #array #hash_table #ordered_set #heap_priority_queue
Telegraph
power-grid-maintenance
给你一个整数 c,表示 c 个电站,每个电站有一个唯一标识符 id,从 1 到 c 编号。 这些电站通过 n 条 双向 电缆互相连接,表示为一个二维数组 connections,其中每个元素 connections[i] = [ui, vi] 表示电站 ui 和电站 vi 之间的连接。直接或间接连接的电站组成了一个 电网 。 最初,所有 电站均处于在线(正常运行)状态。 另给你一个二维数组 queries,其中每个查询属于以下 两种类型之一 :
leetcode.com 2025-11-06
🟡3607.power-grid-maintenance
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #graph #array #hash_table #ordered_set #heap_priority_queue
🟡3607.power-grid-maintenance
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #graph #array #hash_table #ordered_set #heap_priority_queue
Telegraph
power-grid-maintenance
You are given an integer c representing c power stations, each with a unique identifier id from 1 to c (1‑based indexing). These stations are interconnected via n bidirectional cables, represented by a 2D array connections, where each element connections[i]…