未定义变量

关注

LeetCode 热题100-45-买卖股票的最佳时机

未定义变量

关注

阅读 48

2022-04-13

核心思路:动态规划
思路:
DP式:第i天的最大收益=MAX{前i-1天的最大收益,第i天价格-前i-1天的最低价格}

class Solution {
    public int maxProfit(int[] prices) {
        if(prices.length < 2){
            return 0;
        }
        int max = 0;
        int min = prices[0];
        for(int i = 1; i < prices.length; i++){
            max = Math.max(max,prices[i]-min);
            min = Math.min(min,prices[i]);
        }
        return max;
    }
}

相关推荐

琛彤麻麻

LeetCode 热题 HOT 100 第45天:“买卖股票的最佳时机”

琛彤麻麻 54 0 0

三维控件研究

买卖股票的最佳时机

三维控件研究 63 0 0

单调先生

LeetCode刷题(41)~买卖股票的最佳时机

单调先生 59 0 0

妖妖妈

Leetcode-买卖股票的最佳时机

妖妖妈 56 0 0

热爱生活的我一雷广琴

LeetCode.买卖股票的最佳时机 II

热爱生活的我一雷广琴 89 0 0

青青子衿谈育儿

算法- 买卖股票的最佳时机

青青子衿谈育儿 86 0 0

萧让听雪

leetcode简单题 -- 09.买卖股票的最佳时机

萧让听雪 49 0 0

夕颜合欢落

LeetCode121 买卖股票的最佳时机

夕颜合欢落 36 0 0

艾米吖

Leetcode 121.买卖股票的最佳时机

艾米吖 49 0 0

承蒙不弃

LeetCode-121-买卖股票的最佳时机

承蒙不弃 73 0 0

精彩评论(0)

0 0 举报