Algorithms—122.Best Time to Buy and Sell Stock II
2015-06-22 00:39
489 查看
思路:比121题更简单,不限制交易次数。
public class Solution { public int maxProfit(int[] prices) { if (prices.length <= 1) { return 0; } int[] change = new int[prices.length - 1]; for (int i = 0; i < change.length; i++) { change[i] = prices[i + 1] - prices[i]; } int sum = 0; for (int i = 0; i < change.length; i++) { if (change[i]>0) { sum+=change[i]; } } return sum; } }
相关文章推荐
- Algorithms—121.Best Time to Buy and Sell Stock
- Google GFS文件系统深入分析
- Google GFS文件系统深入分析
- poj3622 Gourmet Grazers(贪心+Treap)
- 学习Rust Book之写Cargo配置文件
- Uva - 11054 - Wine trading in Gergovia
- Uva - 11054 - Wine trading in Gergovia
- .pb.h:9:42: fatal error: google/protobuf/stubs/common.h: No such file or directory
- EGORefreshTableHeaderView学习
- django 简单会议室预约(1)
- OGRE1.7以上版本隐藏LOGO及鼠标拾取物体关键
- 使用 Google
- ubuntu 安装 google Gtest
- Django学习日记05_模板_模板语言
- Django学习日记04_模板_overview
- MIT algorithm 笔记(视频2)
- In machine learning, is more data always better than better algorithms?
- 返回书签 GotoBookmark
- django1.7写一个MOOC管理系统(一:基本配置)(2015.6.20)
- google host 配置