leetcode Best Time to Buy and Sell Stock

//有个图片解释,需要编辑模式才能看。。。。

class Solution { public int maxProfit(int[] prices) { int minprice = Integer.MAX_VALUE; int profit = 0; for(int i=0;i<prices.length;i++){ if(prices[i]<minprice){ minprice = prices[i]; } else if(prices[i]-minprice>profit){ profit = prices[i]-minprice; } } return profit; } }

                                                                                                     

posted @ 2018-03-31 23:40  mstark  阅读(110)  评论(0编辑  收藏  举报