Untitled
unknown
plain_text
2 years ago
439 B
7
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...