题解 | #买卖股票的最好时机(一)#

买卖股票的最好时机(一)

http://www.nowcoder.com/practice/64b4262d4e6d4f6181cd45446a5821ec

//动态规划思路

public class Solution { /** * * @param prices int整型一维数组 * @return int整型 */ public int maxProfit (int[] prices) { // write code here int maxProfit = 0; int start = 0; int end = 1; while(end < prices.length){ //如果end位置的值-start位置的值小于0,start = end,否则将end处卖出的值与maxProfit比较 if(prices[end] - prices[start] < 0){ start = end; } maxProfit = prices[end] - prices[start] > maxProfit? prices[end] - prices[start]: maxProfit; end++; } return maxProfit; } }

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-08 13:15
点赞 评论 收藏
分享
zzzzhz:兄弟你先猛猛投简历至少三百家,能约到面试就去面。最近可以速成智能小车,智慧家居烂大街的项目,不需要自己写,只需要把里面的代码讲解看明白就行。把其中涉及到的八股文都拿出来单独背一下,我去年找工作就一个智能小车智慧家居找了10k差不多。
点赞 评论 收藏
分享
点赞 评论 收藏
分享
昨天 13:47
门头沟学院 Java
投递小米集团等公司7个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务