美文网首页
best-time-to-buy-and-sell-stock-

best-time-to-buy-and-sell-stock-

作者: DaiMorph | 来源:发表于2019-07-21 22:08 被阅读0次
class Solution {
public:
    int maxProfit(vector<int> &prices) {
        int res=0;
        for(int i=1;i<prices.size();i++)
        {
            if(prices[i]-prices[i-1]>0)
                res+=prices[i]-prices[i-1];
        }
        return res;
    }
};

相关文章

网友评论

      本文标题:best-time-to-buy-and-sell-stock-

      本文链接:https://www.haomeiwen.com/subject/dkxblctx.html