题目链接 解题思路1:因为交易次数不受限,如果可以把所有的上坡全部收集到,一定是利益最大化的。 class Solution { public: int maxProfit(vector<int>& prices) { if (prices.empty() || prices.size() <= 1 Read More
posted @ 2021-03-31 17:33 洗盏更酌 Views(28) Comments(0) Diggs(0) Edit
题目链接 解题思路: 只需要遍历价格数组一遍,记录历史最低点,然后在每一天考虑这么一个问题:如果a56爆大奖在线娱乐是在历史最低点买进的,那么a56爆大奖在线娱乐今天卖出能赚多少钱?当考虑完所有天数之时,a56爆大奖在线娱乐们就得到了最好的答案。 C++: class Solution { public: int maxProfit(vector<in Read More
posted @ 2021-03-31 16:48 洗盏更酌 Views(41) Comments(0) Diggs(0) Edit