class Solution:
def maxProfit(self, prices) -> int:
result, buy = 0, prices[0]
for p in prices:
result, buy = max(result, p - buy), min(buy, p)
return result
121. Best Time to Buy and Sell Stock - LeetCode
ยท One min read