12 2022 档案

摘要: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 阅读(13) 评论(0) 推荐(0) 编辑
摘要:1754. 构造字典序最大的合并字符串 题解: 每次从word1 和 word2 中取首字符 添加到merge字符串中,使得merge字符串字典序最大 比较word1 和 word2 的首字符,谁大用谁的 如果word1 和 word2 的首字符相等,此时需要比较word1 和 word2的字典序谁 阅读全文
posted @ 2022-12-24 12:41 Eiffelzero 阅读(28) 评论(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 阅读(12) 评论(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 阅读(20) 评论(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 阅读(15) 评论(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 阅读(21) 评论(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 阅读(16) 评论(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 阅读(17) 评论(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 阅读(11) 评论(0) 推荐(0) 编辑
摘要:1945. 字符串转化后的各位数字之和 题解: 按题意模拟 先将英文字母转成数字 每转一轮数字,下一轮数字为上一轮数字的每位之和 class Solution { public int getLucky(String s, int k) { StringBuilder stringBuilder = 阅读全文
posted @ 2022-12-15 20:58 Eiffelzero 阅读(29) 评论(0) 推荐(0) 编辑
摘要:1832. 判断句子是否为全字母句 class Solution { public boolean checkIfPangram(String sentence) { char[] chars = sentence.toCharArray(); int[] flag = new int[30]; f 阅读全文
posted @ 2022-12-13 00:19 Eiffelzero 阅读(14) 评论(0) 推荐(0) 编辑
摘要:1827. 最少操作使数组递增 class Solution { public int minOperations(int[] nums) { int n = nums.length; int res = 0; for(int i = 1; i < n ; i++) { if(nums[i] <= 阅读全文
posted @ 2022-12-11 18:27 Eiffelzero 阅读(25) 评论(0) 推荐(0) 编辑
摘要:(1691. 堆叠长方体的最大高度)[https://leetcode.cn/problems/maximum-height-by-stacking-cuboids/description/] class Solution { public int maxHeight(int[][] cuboids 阅读全文
posted @ 2022-12-10 20:34 Eiffelzero 阅读(19) 评论(0) 推荐(0) 编辑
摘要:1780. 判断一个数字是否可以表示成三的幂的和 题解: 10进制数能否转换成3进制 class Solution { public boolean checkPowersOfThree(int n) { int[] a = new int[20]; a[0] = 1; for (int i = 1 阅读全文
posted @ 2022-12-09 09:45 Eiffelzero 阅读(26) 评论(0) 推荐(0) 编辑
摘要:1775. 通过最少操作次数使数组的和相等 class Solution { public int minOperations(int[] nums1, int[] nums2) { int n = nums1.length, m = nums2.length; if (6 * n < m || 6 阅读全文
posted @ 2022-12-08 00:33 Eiffelzero 阅读(19) 评论(0) 推荐(0) 编辑
摘要:1812. 判断国际象棋棋盘中一个格子的颜色 class Solution { public boolean squareIsWhite(String str) { int a = str.charAt(0) - 'a' + 1; int b = str.charAt(1) - '0'; retur 阅读全文
posted @ 2022-12-08 00:31 Eiffelzero 阅读(12) 评论(0) 推荐(0) 编辑
摘要:1805. 字符串中不同整数的数目 class Solution { public int numDifferentIntegers(String word) { char[] chars = word.toCharArray(); int n = chars.length; Set<String> 阅读全文
posted @ 2022-12-06 18:26 Eiffelzero 阅读(19) 评论(0) 推荐(0) 编辑
摘要:1774. 最接近目标价格的甜点成本 暴力 class Solution { List<Integer> list = new ArrayList<>(); int m; int t; public int closestCost(int[] baseCosts, int[] toppingCost 阅读全文
posted @ 2022-12-04 03:10 Eiffelzero 阅读(22) 评论(0) 推荐(0) 编辑
摘要:1796. 字符串中第二大的数字 class Solution { public int secondHighest(String s) { int max1 = -1; int max2 = -1; char[] ch = s.toCharArray(); int n = ch.length; f 阅读全文
posted @ 2022-12-03 03:03 Eiffelzero 阅读(17) 评论(0) 推荐(0) 编辑
摘要:1769. 移动所有球到每个盒子所需的最小操作数 class Solution { public int[] minOperations(String boxes) { char[] chars = boxes.toCharArray(); int n = chars.length; int[] r 阅读全文
posted @ 2022-12-02 01:29 Eiffelzero 阅读(18) 评论(0) 推荐(0) 编辑
摘要:1779. 找到最近的有相同 X 或 Y 坐标的点 class Solution { public int nearestValidPoint(int x, int y, int[][] points) { int n = points.length; int res = (int)0x3f3f3f 阅读全文
posted @ 2022-12-01 09:00 Eiffelzero 阅读(30) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示