Untitled
unknown
plain_text
a year ago
439 B
0
Indexable
Never
class Solution: def maxProfit(self, prices: List[int]) -> int: N = len(prices) stack = [] globalMax = 0 for i in range(N): while stack and stack[-1] > prices[i]: stack.pop() if stack: globalMax = max(globalMax, prices[i] - stack[0]) stack.append(prices[i]) return globalMax