链接: https://oj.leetcode.com/problems/best-time-to-buy-and-sell-stock/
开始理解错题意了..
只能买一次&&卖一次.找出最大利润
class Solution { public: int maxProfit(vector<int> &prices) { if(prices.size()==0) return 0; int ans=0; int min=prices[0]; for(int i=1;i<prices.size();i++) { if(prices[i]<min) { min=prices[i]; } else { if(prices[i]-min>ans) ans=prices[i]-min; } } return ans; } };
天下武功,唯快不破