121. Best Time to Buy and Sell Stock
- keep the left pointer at the lowest position
class Solution:
def maxProfit(self, prices: List[int]) -> int:
l, r = 0, 1
curMax = 0
while r < len(prices):
if prices[r] - prices[l] >= 0:
curMax = max(curMax, prices[r] - prices[l])
else:
l = r
r += 1
return curMax