121Best Time to Buy and Sell Stock
来源:互联网 发布:淘宝应该怎么做 编辑:程序博客网 时间:2024/06/16 09:37
class Solution(object):
def maxProfit(self, prices):
"""
:type prices: List[int]
:rtype: int
"""
if not prices or len(prices)==0:
return 0
profit=0
min_price=prices[0]
for i in range(1,len(prices)):
profit=max(profit,prices[i]-min_price)
min_price=min(min_price,prices[i])
def maxProfit(self, prices):
"""
:type prices: List[int]
:rtype: int
"""
if not prices or len(prices)==0:
return 0
profit=0
min_price=prices[0]
for i in range(1,len(prices)):
profit=max(profit,prices[i]-min_price)
min_price=min(min_price,prices[i])
return profit
记录买入最小值
记录每一步的最大利润
最大利润为当前值减去最小值
阅读全文
0 0
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time To Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- SEI各种语法以及SEI消息在解码、显示或其它过程中起辅助作用
- HBase 创建表预分区
- java中正则匹配的贪婪模式和非贪婪模式
- DistMesh
- Android studio编译报错:Error:Execution failed for task ':app:transformClassesWithDexForDebug'
- 121Best Time to Buy and Sell Stock
- 支持向量机(SVM):基本原理
- 树莓派3B ssh登录 密码无限错误
- redis主从复制
- MPAndroidChart之LinChart(3)scale缩放
- IPC-命名管道(FIFO)
- Android 之 内存管理
- Maven Rollback a Release
- Android在Activity中获取手机屏幕的宽高