08 2024 档案

摘要:https://leetcode.cn/problems/integer-break/ dp,思路较为巧妙,需要考虑一个数至少能拆成两份这个点,且需要考虑到拆的这个数的值域是多少(1,i-1),来划分子集且选择拆一次还是拆多次 class Solution { public: int integer 阅读全文
posted @ 2024-08-31 23:15 风乐 阅读(16) 评论(0) 推荐(0)
摘要:简单dphttps://leetcode.cn/problems/unique-paths-ii/description/ 传统做法: class Solution { public: int uniquePathsWithObstacles(vector<vector<int>>& obstacl 阅读全文
posted @ 2024-08-31 22:34 风乐 阅读(14) 评论(0) 推荐(0)
摘要:https://leetcode.cn/problems/binary-tree-cameras/description/ 结合二叉树的贪心题,思路较难想出 /** * Definition for a binary tree node. * public class TreeNode { * in 阅读全文
posted @ 2024-08-31 03:06 风乐 阅读(19) 评论(0) 推荐(0)
摘要:https://leetcode.cn/problems/monotone-increasing-digits/description/ class Solution { public int monotoneIncreasingDigits(int n) { // 返回单调递增的最大数字 // 思 阅读全文
posted @ 2024-08-30 22:03 风乐 阅读(11) 评论(0) 推荐(0)
摘要:https://leetcode.cn/problems/merge-intervals/description/ 经典题合并区间 class Solution { public int[][] merge(int[][] intervals) { Arrays.sort(intervals,(a, 阅读全文
posted @ 2024-08-29 18:36 风乐 阅读(20) 评论(0) 推荐(0)
摘要:https://leetcode.cn/problems/partition-labels/description/ 听说这题是字节广告一面的题有两种做法,但是思路大致相同,主要思路是先求出所有字符的出现的最远距离,然后不断往后遍历,更新当前片段的最远距离 若是第一种做法,就是放在另一个循环中,不断 阅读全文
posted @ 2024-08-29 16:43 风乐 阅读(13) 评论(0) 推荐(0)
摘要:https://leetcode.cn/problems/non-overlapping-intervals/description/ 贪心:思路是更新重叠的区间 class Solution { public int eraseOverlapIntervals(int[][] intervals) 阅读全文
posted @ 2024-08-29 15:38 风乐 阅读(17) 评论(0) 推荐(0)
摘要:https://leetcode.cn/problems/minimum-number-of-arrows-to-burst-balloons/description/ 思路是排序,方便计算气球重叠,难点是在重叠时更新右边界,更新为 两个区间的最右重合点,因为这个点是最少一支箭就可以射掉两个气球的最 阅读全文
posted @ 2024-08-29 14:55 风乐 阅读(29) 评论(0) 推荐(0)
摘要:https://leetcode.cn/problems/queue-reconstruction-by-height/submissions/ 贪心:大致思路是排序,但是可以先排k再排h,或者是先排h再排k,这里只能穷举,发现第一种不合法于是使用第二种,先按照h排序,然后由于h有序了(从大到小降序 阅读全文
posted @ 2024-08-28 02:43 风乐 阅读(12) 评论(0) 推荐(0)
摘要:https://leetcode.cn/problems/lemonade-change/description/ 贪心: 由于 10 美元钞票只能用于 20 美元的找零,而 5 美元钞票既可以用于 20 美元的找零,又可以用于 10 美元的找零,更加通用(使用场景更多),所以如果可以用 10 美元 阅读全文
posted @ 2024-08-28 02:05 风乐 阅读(7) 评论(0) 推荐(0)
摘要:https://leetcode.cn/problems/candy/description/ 贪心,策略是确定一侧的正确性,再确定另一侧的正确性,最后综合作为正确答案,其中先确定一侧的正确性是局部最优,确定两侧的正确性的局部最优,且找不到反例就可以推出全局最优答案 class Solution { 阅读全文
posted @ 2024-08-27 21:47 风乐 阅读(19) 评论(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 风乐 阅读(16) 评论(0) 推荐(0)