121. Best Time to Buy and Sell Stock

Posted The Tech Road

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了121. Best Time to Buy and Sell Stock相关的知识,希望对你有一定的参考价值。

class Solution {
public:
    int maxProfit(vector<int>& prices) {
        if (prices.size() == 0) return 0;
        int res = 0, _min = prices[0];
        for (auto p : prices) {
            if (p < _min)
                _min = p;
            res = max(res, p - _min);
        }
        return res;
    }
};

 

以上是关于121. Best Time to Buy and Sell Stock的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode 121. Best Time to Buy and Sell Stock

121. Best Time to Buy and Sell Stock

121. Best Time to Buy and Sell Stock

121. Best Time to Buy and Sell Stockeasy

121. Best Time to Buy and Sell Stock

121. Best Time to Buy and Sell Stock