You are viewing a single comment's thread. Return to all comments →
def getMax(operations: List[str]) -> List[int]: stack = [] max_stack = [] result = [] for oper in operations: command, *args = map(int, oper.split()) match command: case 1: value = args[0] stack.append(value) if not max_stack or value >= max_stack[-1]: max_stack.append(value) case 2: if stack.pop() == max_stack[-1]: max_stack.pop() case 3: result.append(max_stack[-1]) return result
Seems like cookies are disabled on this browser, please enable them to open this website
Maximum Element
You are viewing a single comment's thread. Return to all comments →