首页 > 其他 > 详细

leetcode Best Time to Buy and Sell Stock

时间:2018-04-01 00:29:21      阅读:214      评论:0      收藏:0      [点我收藏+]
//有个图片解释,需要编辑模式才能看。。。。

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; } }

                                                                                                      技术分享图片

leetcode Best Time to Buy and Sell Stock

原文:https://www.cnblogs.com/mxk-star/p/8684778.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!