解题思路
做了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;}
};