摘要: 808. 分汤 题解: 先对n进行优化,除以25 上取整 分析A和B汤 | A | B | 概率 | | | | | | <=0 | <=0 | 0.5 | | >0 | <=0 | 0 | | <=0 | >0 | 1 | | >0 | >0 | f[i][j] = (f[i-4][j] + f[ 阅读全文
posted @ 2022-11-21 23:00 Eiffelzero 阅读(43) 评论(0) 推荐(0)
摘要: 1732. 找到最高海拔 class Solution { public int largestAltitude(int[] gain) { int res = 0; int high = 0; for(int i = 0; i < gain.length; i ++) { high += gain 阅读全文
posted @ 2022-11-19 16:49 Eiffelzero 阅读(26) 评论(0) 推荐(0)
摘要: 891. 子序列宽度之和 题解: 对于每个数a而言,其对res的贡献在于 a * a作为最大值的次数 - a * a作为最小值的次数 先将数组排序 a 作为最大值的次数: a的下标为i, 比a小的数有 0 ~ i-1 总共i个数,则 为 $$2^i$$ 个 a 作为最小值的次数: a的下标为i, 比 阅读全文
posted @ 2022-11-18 18:46 Eiffelzero 阅读(20) 评论(0) 推荐(0)
摘要: 792. 匹配子序列的单词数 // 时间复杂度 n + m * k public int numMatchingSubseq(String s, String[] words) { List<List<Pair>> list = new ArrayList<>(); for (int i = 0; 阅读全文
posted @ 2022-11-17 23:39 Eiffelzero 阅读(28) 评论(0) 推荐(0)
摘要: 775. 全局倒置与局部倒置 题解: 用归并排序求全局倒置(逆序对) 可以用树状数组求逆序对 class Solution { int num2 = 0; public boolean isIdealPermutation(int[] nums) { int n = nums.length; if 阅读全文
posted @ 2022-11-16 17:44 Eiffelzero 阅读(18) 评论(0) 推荐(0)
摘要: 1710. 卡车上的最大单元数 class Solution { public int maximumUnits(int[][] boxTypes, int truckSize) { int n = boxTypes.length; Arrays.sort(boxTypes, Comparator. 阅读全文
posted @ 2022-11-15 19:32 Eiffelzero 阅读(20) 评论(0) 推荐(0)
摘要: 791. 自定义字符串排序 class Solution { int[] w = new int[30]; public String customSortString(String order, String s) { for (int i =0 ; i < 26;i ++) { w[i] = 3 阅读全文
posted @ 2022-11-13 17:55 Eiffelzero 阅读(29) 评论(0) 推荐(0)
摘要: 790. 多米诺和托米诺平铺 题解: dp num数组表示的是:i-1列的瓷砖都被铺满了,第i列的状态枚举 第i列的状态枚举有4种: 11 表示 上下两行都被填充, 10 表示上面那行被填充, 01 表示下面那行被填充, 00 表示两行都没有被填充 转移方程: num[i+1][k] = num[i 阅读全文
posted @ 2022-11-12 14:14 Eiffelzero 阅读(43) 评论(0) 推荐(0)
摘要: 34. 在排序数组中查找元素的第一个和最后一个位置 class Solution { public int[] searchRange(int[] nums, int target) { if (nums.length == 0) return new int[]{-1, -1}; // 搜左边界 阅读全文
posted @ 2022-11-11 14:21 Eiffelzero 阅读(22) 评论(0) 推荐(0)
摘要: 35. 搜索插入位置 class Solution { public int searchInsert(int[] nums, int target) { int l = 0, r = nums.length - 1; while (l < r) { int mid = l + ((r - l) > 阅读全文
posted @ 2022-11-11 13:03 Eiffelzero 阅读(22) 评论(0) 推荐(0)