当前位置: 代码迷 >> 综合 >> leetcode练习题 best-time-to-buy-and-sell-stock
  详细解决方案

leetcode练习题 best-time-to-buy-and-sell-stock

热度:60   发布时间:2023-12-15 10:04:29.0

解题思路

做了best-time-to-buy-and-sell-stock iii后,这一题算是其简化版。

代码

#include<algorithm>
class Solution {
public:int maxProfit(vector<int> &prices) {int buy1 = INT_MIN,sell1 = 0;for(int i = 0;i < prices.size();i++){buy1 = max(buy1,-prices[i]);sell1 = max(sell1,buy1 + prices[i]);}return sell1;}
};
  相关解决方案