摘要: 买卖股票的最佳时机II 题目链接:122. 买卖股票的最佳时机 II - 力扣(LeetCode) 思路:本题的贪心法在于用不选择亏钱的买卖,某天能赚钱就一定出手,每天都赚钱从而获得总体的最大利益。具体是计算每一天的利润后,如果大于0,就记入总利益。 class Solution { public: 阅读全文
posted @ 2024-02-29 15:56 SandaiYoung 阅读(10) 评论(0) 推荐(0)
摘要: 理论基础 贪心的本质是选择每一阶段的局部最优,从而达到全局最优。 分发饼干 class Solution { public: int findContentChildren(vector<int>& g, vector<int>& s) { sort(g.begin(), g.end()); sor 阅读全文
posted @ 2024-02-29 01:18 SandaiYoung 阅读(13) 评论(0) 推荐(0)