leetcode.cn 2026-04-21
🟡1722.minimize-hamming-distance-after-swap-operations
🏷️ Tags
#depth_first_search #union_find #array
🟡1722.minimize-hamming-distance-after-swap-operations
🏷️ Tags
#depth_first_search #union_find #array
Telegraph
minimize-hamming-distance-after-swap-operations
给你两个整数数组 source 和 target ,长度都是 n 。还有一个数组 allowedSwaps ,其中每个 allowedSwaps[i] = [ai, bi] 表示你可以交换数组 source 中下标为 ai 和 bi(下标从 0 开始)的两个元素。注意,你可以按 任意 顺序 多次 交换一对特定下标指向的元素。 相同长度的两个数组 source 和 target 间的 汉明距离 是元素不同的下标数量。形式上,其值等于满足 source[i] != target[i] (下标从 0 开始)的下标…
leetcode.com 2026-04-21
🟡1722.minimize-hamming-distance-after-swap-operations
🏷️ Tags
#depth_first_search #union_find #array
🟡1722.minimize-hamming-distance-after-swap-operations
🏷️ Tags
#depth_first_search #union_find #array
Telegraph
minimize-hamming-distance-after-swap-operations
You are given two integer arrays, source and target, both of length n. You are also given an array allowedSwaps where each allowedSwaps[i] = [ai, bi] indicates that you are allowed to swap the elements at index ai and index bi (0-indexed) of array source.…
leetcode.cn 2026-04-25
🔴3464.maximize-the-distance-between-points-on-a-square
🏷️ Tags
#geometry #array #math #binary_search #sorting
🔴3464.maximize-the-distance-between-points-on-a-square
🏷️ Tags
#geometry #array #math #binary_search #sorting
Telegraph
maximize-the-distance-between-points-on-a-square
给你一个整数 side,表示一个正方形的边长,正方形的四个角分别位于笛卡尔平面的 (0, 0) ,(0, side) ,(side, 0) 和 (side, side) 处。
leetcode.com 2026-04-25
🔴3464.maximize-the-distance-between-points-on-a-square
🏷️ Tags
#geometry #array #math #binary_search #sorting
🔴3464.maximize-the-distance-between-points-on-a-square
🏷️ Tags
#geometry #array #math #binary_search #sorting
Telegraph
maximize-the-distance-between-points-on-a-square
You are given an integer side, representing the edge length of a square with corners at (0, 0), (0, side), (side, 0), and (side, side) on a Cartesian plane. You are also given a positive integer k and a 2D integer array points, where points[i] = [xi, yi]…
leetcode.cn 2026-04-26
🟡1559.detect-cycles-in-2d-grid
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #array #matrix
🟡1559.detect-cycles-in-2d-grid
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #array #matrix
Telegraph
detect-cycles-in-2d-grid
给你一个二维字符网格数组 grid ,大小为 m x n ,你需要检查 grid 中是否存在 相同值 形成的环。 一个环是一条开始和结束于同一个格子的长度 大于等于 4 的路径。对于一个给定的格子,你可以移动到它上、下、左、右四个方向相邻的格子之一,可以移动的前提是这两个格子有 相同的值 。 同时,你也不能回到上一次移动时所在的格子。比方说,环 (1, 1) -> (1, 2) -> (1, 1) 是不合法的,因为从 (1, 2) 移动到 (1, 1) 回到了上一次移动时的格子。 如果 grid 中有相同值形成的环,请你返回…
leetcode.com 2026-04-26
🟡1559.detect-cycles-in-2d-grid
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #array #matrix
🟡1559.detect-cycles-in-2d-grid
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #array #matrix
Telegraph
detect-cycles-in-2d-grid
Given a 2D array of characters grid of size m x n, you need to find if there exists any cycle consisting of the same value in grid. A cycle is a path of length 4 or more in the grid that starts and ends at the same cell. From a given cell, you can move to…
leetcode.cn 2026-04-27
🟡1391.check-if-there-is-a-valid-path-in-a-grid
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #array #matrix
🟡1391.check-if-there-is-a-valid-path-in-a-grid
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #array #matrix
Telegraph
check-if-there-is-a-valid-path-in-a-grid
给你一个 m x n 的网格 grid。网格里的每个单元都代表一条街道。grid[i][j] 的街道可以是:
leetcode.com 2026-04-27
🟡1391.check-if-there-is-a-valid-path-in-a-grid
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #array #matrix
🟡1391.check-if-there-is-a-valid-path-in-a-grid
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #array #matrix
Telegraph
check-if-there-is-a-valid-path-in-a-grid
You are given an m x n grid. Each cell of grid represents a street. The street of grid[i][j] can be:
leetcode.cn 2026-04-28
🟡2033.minimum-operations-to-make-a-uni-value-grid
🏷️ Tags
#array #math #matrix #sorting
🟡2033.minimum-operations-to-make-a-uni-value-grid
🏷️ Tags
#array #math #matrix #sorting
Telegraph
minimum-operations-to-make-a-uni-value-grid
给你一个大小为 m x n 的二维整数网格 grid 和一个整数 x 。每一次操作,你可以对 grid 中的任一元素 加 x 或 减 x 。 单值网格 是全部元素都相等的网格。 返回使网格化为单值网格所需的 最小 操作数。如果不能,返回 -1 。 示例 1: 输入:grid = [[2,4],[6,8]], x = 2 输出:4 解释:可以执行下述操作使所有元素都等于 4 : - 2 加 x 一次。 - 6 减 x 一次。 - 8 减 x 两次。 共计 4 次操作。 示例 2: 输入:grid = [[1…
leetcode.com 2026-04-28
🟡2033.minimum-operations-to-make-a-uni-value-grid
🏷️ Tags
#array #math #matrix #sorting
🟡2033.minimum-operations-to-make-a-uni-value-grid
🏷️ Tags
#array #math #matrix #sorting
Telegraph
minimum-operations-to-make-a-uni-value-grid
You are given a 2D integer grid of size m x n and an integer x. In one operation, you can add x to or subtract x from any element in the grid. A uni-value grid is a grid where all the elements of it are equal. Return the minimum number of operations to make…
leetcode.cn 2026-04-29
🔴3225.maximum-score-from-grid-operations
🏷️ Tags
#array #dynamic_programming #matrix #prefix_sum
🔴3225.maximum-score-from-grid-operations
🏷️ Tags
#array #dynamic_programming #matrix #prefix_sum
Telegraph
maximum-score-from-grid-operations
给你一个大小为 n x n 的二维矩阵 grid ,一开始所有格子都是白色的。一次操作中,你可以选择任意下标为 (i, j) 的格子,并将第 j 列中从最上面到第 i 行所有格子改成黑色。 如果格子 (i, j) 为白色,且左边或者右边的格子至少一个格子为黑色,那么我们将 grid[i][j] 加到最后网格图的总分中去。 请你返回执行任意次操作以后,最终网格图的 最大 总分数。 示例 1: 输入:grid = [[0,0,0,0,0],[0,0,3,0,0],[0,1,0,0,0],[5,0,0,3…
leetcode.com 2026-04-29
🔴3225.maximum-score-from-grid-operations
🏷️ Tags
#array #dynamic_programming #matrix #prefix_sum
🔴3225.maximum-score-from-grid-operations
🏷️ Tags
#array #dynamic_programming #matrix #prefix_sum
Telegraph
maximum-score-from-grid-operations
You are given a 2D matrix grid of size n x n. Initially, all cells of the grid are colored white. In one operation, you can select any cell of indices (i, j), and color black all the cells of the jth column starting from the top row down to the ith row. The…