https://leetcode.com/problems/best-time-to-buy-and-sell-stock/
滑动更新最低价、最大收益值。
class Solution {
public:int maxProfit(vector<int>& prices) {int n = prices.size();if(n<2) return 0;int p = 0;int low = prices[0];int i;//滑动更新最小值、收益最大值for(i=1;i<n;i++){if(prices[i]>low){if(p<prices[i]-low)p = prices[i]-low;}elselow = prices[i];}return p;}
};