上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 22 下一页
摘要: https://leetcode.cn/problems/merge-intervals/description/ 经典题合并区间 class Solution { public int[][] merge(int[][] intervals) { Arrays.sort(intervals,(a, 阅读全文
posted @ 2024-08-29 18:36 风乐 阅读(28) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/partition-labels/description/ 听说这题是字节广告一面的题有两种做法,但是思路大致相同,主要思路是先求出所有字符的出现的最远距离,然后不断往后遍历,更新当前片段的最远距离 若是第一种做法,就是放在另一个循环中,不断 阅读全文
posted @ 2024-08-29 16:43 风乐 阅读(27) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/non-overlapping-intervals/description/ 贪心:思路是更新重叠的区间 class Solution { public int eraseOverlapIntervals(int[][] intervals) 阅读全文
posted @ 2024-08-29 15:38 风乐 阅读(27) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/minimum-number-of-arrows-to-burst-balloons/description/ 思路是排序,方便计算气球重叠,难点是在重叠时更新右边界,更新为 两个区间的最右重合点,因为这个点是最少一支箭就可以射掉两个气球的最 阅读全文
posted @ 2024-08-29 14:55 风乐 阅读(40) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/queue-reconstruction-by-height/submissions/ 贪心:大致思路是排序,但是可以先排k再排h,或者是先排h再排k,这里只能穷举,发现第一种不合法于是使用第二种,先按照h排序,然后由于h有序了(从大到小降序 阅读全文
posted @ 2024-08-28 02:43 风乐 阅读(21) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/lemonade-change/description/ 贪心: 由于 10 美元钞票只能用于 20 美元的找零,而 5 美元钞票既可以用于 20 美元的找零,又可以用于 10 美元的找零,更加通用(使用场景更多),所以如果可以用 10 美元 阅读全文
posted @ 2024-08-28 02:05 风乐 阅读(20) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/candy/description/ 贪心,策略是确定一侧的正确性,再确定另一侧的正确性,最后综合作为正确答案,其中先确定一侧的正确性是局部最优,确定两侧的正确性的局部最优,且找不到反例就可以推出全局最优答案 class Solution { 阅读全文
posted @ 2024-08-27 21:47 风乐 阅读(28) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/gas-station/ 贪心,原理是: 如果x能到达y,不能到达y+1,那么x-y之间的点也不可能到达y+1:z为xy之间一点,从x开始到z(在z加油前),剩余油量一定大等于0,但是从z开始的话,起始油量一定等于0 >> 起始油量大等于0都 阅读全文
posted @ 2024-08-24 00:03 风乐 阅读(27) 评论(0) 推荐(0)
摘要: https://www.nowcoder.com/practice/22948c2cad484e0291350abad86136c3?tpId=37&tqId=21331&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta% 阅读全文
posted @ 2024-06-15 01:44 风乐 阅读(41) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/combination-sum-ii/description/ class Solution { List<List<Integer>> res = new ArrayList<>(); LinkedList<Integer> path = 阅读全文
posted @ 2024-05-16 12:41 风乐 阅读(22) 评论(0) 推荐(0)
上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 22 下一页