好忙这几天,偷个懒小做一点,后面有空补回来
题目链接:121. 买卖股票的最佳时机 - 力扣(LeetCode)
class Solution {
public:int maxProfit(vector<int>& prices) {int minr=INT_MAX;int result=0;for(int i=0;i<prices.size();i++){minr=min(minr,prices[i]);result=max(prices[i]-minr,result);}return result;}
};
贪心了,想不出怎么dp