122 Best Time to Buy and Sell Stock II
2015-11-23 14:09
288 查看
与一非常类似。只需要改一个条件。
public class Solution { public int maxProfit(int[] prices) { if (prices == null || prices.length <= 1) { return 0; } int max = Integer.MIN_VALUE; int sum = 0; for (int i = 1; i < prices.length; i++) { int localprofit = prices[i] - prices[i - 1]; if (localprofit > 0) { sum+=localprofit; } max = Math.max(max, sum); } return max; } }
相关文章推荐
- iOS 关于NSArray中的调用方法
- Leetcode Multiply Strings
- 农商行信息化建设过程中存在哪些问题?
- 农商行信息化建设过程中存在哪些问题?
- spring框架学习(四)自动装配
- 1009. 说反话 (20)
- 【Python】django权限管理
- python帮助信息查看以及笔记
- 如何把运行期警告转移到编译期的几个小技巧
- Eclipse安装SVN插件教程
- AndroidManifest.xml权限设置
- Vijos1647 不差钱
- 麦子学院cocos2d听课截图
- hdoj Co-prime 4135 (容斥原理)
- 根据文件名修改文件(创业天使-xxx 120101_超清.mp4 --> 120101-创业天使-xxx.mp4)
- spring框架学习(三)junit单元测试
- 10段代码打通js学习的任督二脉
- MySQL索引背后的数据结构及算法原理
- SQL SERVER如何通过SQL语句获服务器硬件和系统信息
- 单核CPU,多线程与性能