注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
我的代码如下:
class Solution:
def maxProfit(self, prices: List[int]) -> int:
profit = []
for i in range(len(prices)-1):
prices_start = prices[i]
for j in range(i+1,len(prices)):
prices_end = prices[j]
profit.append(prices_end-prices_start)
if profit is None:
return 0
max_profit = max(profit)
if max_profit <= 0:
return 0
return max_profit
Run code时能accepted, 但是submit时会有如下报错:
ValueError: max() arg is an empty sequence
max_profit = max(profit)
Line 11 in maxProfit (Solution.py)
ret = Solution().maxProfit(param_1)
Line 35 in _driver (Solution.py)
_driver()
Line 46 in <module> (Solution.py)
小弟刚接触python刷leetcode,忘大神指点一二,不胜感激!
|