摘要:
[2011. 执行操作后的变量值] (https://leetcode.cn/problems/final-value-of-variable-after-performing-operations/description/) class Solution { public int finalVal 阅读全文
摘要:
1753. 移除石子的最大得分 题解: 先将a,b,c 预处理为 a <= b <= c 当a + b <= c 时, 【ac】 和 【bc】 轮流取,直到a 和 b 为0 所以答案为 a + b 当a + b > c 时, 设【ac】取k1次, 【bc】取k2次,先将c取完,然后 再【ab】取 直 阅读全文
摘要:
1971. 寻找图中是否存在路径 题解:并查集 并查集模板题 判断两个点是否在同一个连通块 class Solution { int[] p = new int[200010]; int find(int x) { if (p[x] != x) p[x] = find(p[x]); return p 阅读全文
摘要:
1703. 得到连续 K 个 1 的最少相邻交换次数 class Solution { public int minMoves(int[] nums, int k) { List<Integer> g = new ArrayList<Integer>(); List<Integer> preSum 阅读全文
摘要:
1764. 通过连接另一个数组的子数组得到一个数组 题解: 数据范围小,直接暴力 双指针 public boolean canChoose(int[][] groups, int[] nums) { int n = groups.length; int length = nums.length; i 阅读全文
摘要:
1785. 构成特定和需要添加的最少元素 题解: 求数组和a 和 goal 的距离 每次取最大的limit,如果不能整除 则答案还要加一 class Solution { public int minElements(int[] nums, int limit, int goal) { long s 阅读全文