122. Best Time to Buy and Sell Stock II
来源:互联网 发布:北京美工培训 编辑:程序博客网 时间:2024/06/16 06:17
Say you have an array for which the ith element is the price of a given stock on day i.
Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).
class Solution(object): def maxProfit(self, prices): cnt = len(prices) tmp_profit = 0 for i in range(cnt-1): if prices[i+1]-prices[i]>0: tmp_profit+=prices[i+1] - prices[i] return tmp_profit
阅读全文
0 0
- 122. Best Time to Buy and Sell Stock II
- LeetCode 122. Best Time to Buy and Sell Stock II
- 122.Best Time to Buy and Sell Stock II
- [Leetcode] 122. Best Time to Buy and Sell Stock II
- [leetcode] 122.Best Time to Buy and Sell Stock II
- 【leetcode】122.Best Time to Buy and Sell Stock II
- 122. Best Time to Buy and Sell Stock II
- 【LeetCode】122.Best Time to Buy and Sell Stock II
- [leetcode] 122. Best Time to Buy and Sell Stock II
- LeetCode #122. Best Time to Buy and Sell Stock II
- 122. Best Time to Buy and Sell Stock II LeetCode
- 122. Best Time to Buy and Sell Stock II
- 122. Best Time to Buy and Sell Stock II
- 122. Best Time to Buy and Sell Stock II
- [LeetCode]122. Best Time to Buy and Sell Stock II
- 122. Best Time to Buy and Sell Stock II
- Leetcode 122. Best Time to Buy and Sell Stock II
- leetcode 122. Best Time to Buy and Sell Stock II
- jQuery中没有innerText、innerHtml
- java代码while循环实现:500人围成一圈,数3退一,求最后留下的人的最初位置
- Zookeeper学习
- 快速求根和求倒数根算法链接
- Linux上.sh文件中的命令为什么执行不了?
- 122. Best Time to Buy and Sell Stock II
- sql语句的各种模糊查询
- 时间格式化、定时任务
- 父进程异常退出时,确保子进程退出
- sizeof操作符关于类相关使用
- ubuntu安装python-pip问题解决
- Python3读取Excel数据存入MySQL
- iOS block为什么要用copy
- 关于spring boot org.springframework.context.ApplicationContextException:Unable to start Embedded解决方案