摘要: 2032. 至少在两个数组中出现的值 class Solution { public List<Integer> twoOutOfThree(int[] nums1, int[] nums2, int[] nums3) { List<Integer> res = new ArrayList<>(); 阅读全文
posted @ 2022-12-30 00:01 Eiffelzero 阅读(33) 评论(0) 推荐(0)
摘要: 1754. 构造字典序最大的合并字符串 题解: 每次从word1 和 word2 中取首字符 添加到merge字符串中,使得merge字符串字典序最大 比较word1 和 word2 的首字符,谁大用谁的 如果word1 和 word2 的首字符相等,此时需要比较word1 和 word2的字典序谁 阅读全文
posted @ 2022-12-24 12:41 Eiffelzero 阅读(41) 评论(0) 推荐(0)
摘要: [2011. 执行操作后的变量值] (https://leetcode.cn/problems/final-value-of-variable-after-performing-operations/description/) class Solution { public int finalVal 阅读全文
posted @ 2022-12-23 17:45 Eiffelzero 阅读(20) 评论(0) 推荐(0)
摘要: 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】取 直 阅读全文
posted @ 2022-12-21 14:52 Eiffelzero 阅读(30) 评论(0) 推荐(0)
摘要: 1760. 袋子里最少数目的球 题解: 二分 1.题目可以转换为:操作 maxOperations 次,每个袋子的最大值小于等于 ans,求这个ans的最小值 2.可以从[1, nums数组的最大值]这个区间开始二分 3.判断函数: nums[i] <= ans opt = 0 nums[i] > 阅读全文
posted @ 2022-12-20 11:31 Eiffelzero 阅读(23) 评论(0) 推荐(0)
摘要: 1971. 寻找图中是否存在路径 题解:并查集 并查集模板题 判断两个点是否在同一个连通块 class Solution { int[] p = new int[200010]; int find(int x) { if (p[x] != x) p[x] = find(p[x]); return p 阅读全文
posted @ 2022-12-19 18:06 Eiffelzero 阅读(32) 评论(0) 推荐(0)
摘要: 1703. 得到连续 K 个 1 的最少相邻交换次数 class Solution { public int minMoves(int[] nums, int k) { List<Integer> g = new ArrayList<Integer>(); List<Integer> preSum 阅读全文
posted @ 2022-12-18 18:01 Eiffelzero 阅读(27) 评论(0) 推荐(0)
摘要: 1764. 通过连接另一个数组的子数组得到一个数组 题解: 数据范围小,直接暴力 双指针 public boolean canChoose(int[][] groups, int[] nums) { int n = groups.length; int length = nums.length; i 阅读全文
posted @ 2022-12-17 18:31 Eiffelzero 阅读(28) 评论(0) 推荐(0)
摘要: 1785. 构成特定和需要添加的最少元素 题解: 求数组和a 和 goal 的距离 每次取最大的limit,如果不能整除 则答案还要加一 class Solution { public int minElements(int[] nums, int limit, int goal) { long s 阅读全文
posted @ 2022-12-16 23:09 Eiffelzero 阅读(19) 评论(0) 推荐(0)
摘要: 1945. 字符串转化后的各位数字之和 题解: 按题意模拟 先将英文字母转成数字 每转一轮数字,下一轮数字为上一轮数字的每位之和 class Solution { public int getLucky(String s, int k) { StringBuilder stringBuilder = 阅读全文
posted @ 2022-12-15 20:58 Eiffelzero 阅读(46) 评论(0) 推荐(0)