Untitled
Anonymous
plain_text
10/09/2023 6:33 AM
588 B
18
Indexable
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 globalMaxEditor is loading...