码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode(121-123)买股票的最佳时机

时间:2019-09-06 15:44:10      阅读:53      评论:0      收藏:0      [点我收藏+]

标签:max   股票   ++   div   时机   return   price   class   turn   

1、

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

 

leetcode(121-123)买股票的最佳时机

标签:max   股票   ++   div   时机   return   price   class   turn   

原文地址:https://www.cnblogs.com/erdanyang/p/11475103.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!