class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int n = prices.size();
        if (n==0){
            return 0;
        }
        int res = 0;
        int mmin = prices[0];
        for (int i=1;i<n;i++){
            res = max(res,prices[i]-mmin);
            mmin = min(mmin,prices[i]);
        }
        return res;
    }
};

相关文章:

  • 2021-06-15
  • 2021-06-27
  • 2021-10-19
  • 2021-11-23
  • 2021-09-01
猜你喜欢
  • 2021-11-29
相关资源
相似解决方案