leetcode121. 买卖股票的最佳时机

class Solution {
public:
    int maxProfit(vector<int>& prices) {
        vector<int> sk(prices.size(),0);
        int top=-1,ans=0;
        for(auto t:prices){
            while(top!=-1&&sk[top]>=t)top--;
            if(top!=-1)ans=max(t-sk[0],ans);
            sk[++top]=t;
        }
        return ans;
    }
};