leetcode -- Best Time to Buy and Sell Stock II -- 重点注意思路
2015-12-10 22:44
441 查看
https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/
因为可以进行无限次交易,并且在下一次buy之前必须已经sell。所以只需要把所有price曲线价格上涨的部分加起来就行。
参考
/article/4981578.html
因为可以进行无限次交易,并且在下一次buy之前必须已经sell。所以只需要把所有price曲线价格上涨的部分加起来就行。
参考
/article/4981578.html
class Solution(object): def maxProfit(self, prices): """ :type prices: List[int] :rtype: int """ maxprofit = 0 for i in range(1, len(prices)): if prices[i] >= prices[i-1]: maxprofit += prices[i] - prices[i-1] return maxprofit
相关文章推荐
- 自定义TWebBrowser浏览器控制遇到的一些问题
- 关于 Object.prototype.toString.call() 方法
- MySQL的loose index scan
- 10G(82599EB) 网卡测试优化(中断处理)
- python学习之路之案例3--多级菜单显示城市详细信息
- MySQL删除数据Delete 语句、Truncate 语句
- 10G(82599EB) 网卡测试优化(other)
- Android 分组listview 简易实现方法
- 在虚拟机中安装CentOS却无法上网的解决方法
- ubuntu 升级gcc 到4.7
- 杭电 1086 You can Solve a Geometry Problem too 判断线段是否相交.
- install 命令
- 对web的request的全部值进行了提取
- Android 自定义View修炼-自定义加载进度动画XCLoadingImageView
- 六要点实现Unity3D开发性能优化
- iOS运用fabric记录crash日志过程
- 机器学习中的范数规则化之(一)L0、L1与L2范数(转)
- 关于图像合成所引申的几个函数
- 我收录整理的优秀OC技术类文章
- C++ 关联容器