一、leetcode地址
https://leetcode.com/problems/best-time-to-buy-and-sell-stock/
二、问题描述
三、代码实现
语言:Python3
代码:
class Solution:
def maxProfit(self, prices: List[int]) -> int:
if prices:
min_price = prices[0]
else:
return 0
max_profit = 0
for price in prices:
if price < min_price:
min_price = price
if price - min_price > max_profit:
max_profit = price - min_price
return max_profit