121. Best Time to Buy and Sell Stock

来源:互联网 发布:微创软件怎么样 编辑:程序博客网 时间:2024/06/07 16:59
public int maxProfit(int[] prices) {    if(prices.length<2){    return 0;    }        int re=0;        int low=prices[0];        for(int i=1; i<prices.length; i++){        if(prices[i]<low){        low=prices[i];        }else{        re=Math.max(re, prices[i]-low);        }        }        return re;    }


对这类问题还不太熟悉

0 0
原创粉丝点击