美文网首页
121. Best Time to Buy and Sell S

121. Best Time to Buy and Sell S

作者: 夜皇雪 | 来源:发表于2016-12-16 12:32 被阅读0次
public class Solution {
    public int maxProfit(int[] prices) {
        if(prices.length==0) return 0;
        int max=0,minprice=prices[0];
        for(int i=1;i<prices.length;i++){
            if(prices[i]>minprice){
                max=Math.max(max,prices[i]-minprice);
            }else minprice=prices[i];
        }
        return max;
    }
}

相关文章

网友评论

      本文标题:121. Best Time to Buy and Sell S

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