Leetcode 121 Best Time to Buy and Sell Stock
2015-07-04 17:10
309 查看
class Solution:
# @param {integer[]} prices
# @return {integer}
def maxProfit(self, prices):
if len(prices) <= 1: return 0
low = prices[0]; mostProfit = 0
for i in range(1, len(prices)):
if prices[i] < low: low = prices[i]
mostProfit = max(mostProfit, prices[i] - low)
return mostProfit
# @param {integer[]} prices
# @return {integer}
def maxProfit(self, prices):
if len(prices) <= 1: return 0
low = prices[0]; mostProfit = 0
for i in range(1, len(prices)):
if prices[i] < low: low = prices[i]
mostProfit = max(mostProfit, prices[i] - low)
return mostProfit
相关文章推荐
- Intent数据传递(转)
- c语言函数指针的理解与使用
- POJ 3253 Fence Repair
- 一起talk GDB吧(第三回:GDB断点调试)
- 黑红五子棋之人人对弈
- cryptsetup文件系统加密
- linux中Shell标准输出错误 >/dev/null 2>&1 分析
- Leetcode 221 Maximal Square
- 叫号系统排队系统挂号系统实现
- RelativeLayout里的gravity不能居中的解决方法
- 关于Cookie的有关内容
- J.U.C JMM. pipeline.指令重排序,happen-before
- [JavaEE] JBoss主要版本下载链接一览
- mysql 错误号1130
- Leetcode 70 Climbing Stairs
- 利用ns2仿真MANET中的虫洞攻击
- 开始玩hadoop7--hadoop 2.6.0 在eclipse里安装(第一个map程序)
- 提问的智慧(转自github)
- 1004. 成绩排名 (20)
- GM8283:28位可编程数据选通Channel-Link发送器