上一页 1 2 3 4 5 6 7 8 9 10 ··· 22 下一页
摘要: https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-iv/ class Solution { public int maxProfit(int k, int[] prices) { // 由于可以交易k次,以多少次持有来划分状态 阅读全文
posted @ 2024-09-07 02:44 风乐 阅读(24) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-iii/description/ 这一题较难,难点是状态比较多,需要考虑两笔交易,则共5个状态需要被记录,用当前是否持有股票来划分子集进行计算 class Solution { 阅读全文
posted @ 2024-09-06 01:53 风乐 阅读(21) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-ii/description/ class Solution { public: int maxProfit(vector<int>& prices) { vector<int> 阅读全文
posted @ 2024-09-06 00:39 风乐 阅读(17) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/best-time-to-buy-and-sell-stock/ 经典股票题,此题有贪心做法 class Solution { public int maxProfit(int[] prices) { int res = 0; int min 阅读全文
posted @ 2024-09-06 00:13 风乐 阅读(36) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/house-robber-iii/description/基础树形dp,要点是f的定义灵神讲的很好:https://www.bilibili.com/video/BV1vu4y1f7dn/?vd_source=1bb76d0400eba0d4 阅读全文
posted @ 2024-09-05 02:06 风乐 阅读(19) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/house-robber-ii/description/ 灵神题解: https://leetcode.cn/problems/house-robber-ii/solutions/2445622/jian-ji-xie-fa-zhi-jie- 阅读全文
posted @ 2024-09-04 19:49 风乐 阅读(31) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/word-break/description/ class Solution { public boolean wordBreak(String s, List<String> wordDict) { // 思路较为巧妙,和传统背包定义不同 阅读全文
posted @ 2024-09-04 19:14 风乐 阅读(33) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/perfect-squares/description/ 简单完全背包,需要注意的是由于求的是最小,因此初始化时需要把初始层f[0]全置为无穷大,用于保证一定能计算出min具体可以看灵神的解释 递归边界:dfs(0,0)=0,因为没有数可以选 阅读全文
posted @ 2024-09-04 02:48 风乐 阅读(47) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/coin-change/description/ 代码上比较麻烦的dp题,由于求的是最少数量,因此求答案时需要初始化无穷大来计算 class Solution { public int coinChange(int[] coins, int 阅读全文
posted @ 2024-09-03 21:01 风乐 阅读(23) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/combination-sum-iv/description/ 此篇题解解释了为什么不能直接用二维完全背包的方式做不过还是建议把这个题当成一个爬楼梯来做 class Solution { public: int combinationSum4 阅读全文
posted @ 2024-09-03 19:35 风乐 阅读(26) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 8 9 10 ··· 22 下一页