LeetCode OJ 系列之122 Best Time to Buy and Sell Stock II --Python
来源:互联网 发布:淘宝手工护肤哪家好 编辑:程序博客网 时间:2024/06/09 17:39
Problem:
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).
Answer:class Solution(object): def maxProfit(self, prices): """ :type prices: List[int] :rtype: int """ return sum(max(prices[i+1]-prices[i],0) for i in range(len(prices)-1))
0 0
- LeetCode OJ 系列之122 Best Time to Buy and Sell Stock II --Python
- LeetCode OJ 系列之121 Best Time to Buy and Sell Stock --Python
- LeetCode OJ:Best Time to Buy and Sell Stock II
- LeetCode OJ - Best Time to Buy and Sell Stock II
- [LeetCode OJ]Best Time to Buy and Sell Stock II
- LeetCode之Best Time to Buy and Sell Stock II
- LeetCode 之 Best Time to Buy and Sell Stock II
- LeetCode之Best Time to Buy and Sell Stock II
- leetcode之Best Time to Buy and Sell Stock II
- LeetCode之Best Time to Buy and Sell Stock II
- LeetCode 之 Best Time to Buy and Sell Stock II
- leetcode之Best Time to Buy and Sell Stock II
- LeetCode之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
- LeetCode: Best Time to Buy and Sell Stock II [122]
- [leetcode 122] Best Time to Buy and Sell Stock II
- iOS读取CSV文件
- APK Multi-Tool强大的APK反编译工具终极教程
- 图解javascript this指向什么?
- maven编译hadoop(2.6.2)源码(二)
- x86、ARM和MIPS三种主流芯片架构
- LeetCode OJ 系列之122 Best Time to Buy and Sell Stock II --Python
- 普通排序--冒泡排序
- Windows Server 2008 部署webservice(C# .Net)
- BLE睡眠分析(一)
- Apache Commons 工具类介绍及简单使用
- OC_protocol协议介绍(1)
- 站长留言
- Nginx服务器的功能模块
- Camera.culling mask