随笔分类 - 算法 / 栈
摘要:239. 滑动窗口最大值 class Solution: def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]: res = [] tmp = MyQueue() for i in range(k): tmp.push(nu
阅读全文
摘要:20. 有效的括号 思路:分析出三种情况,画图模拟。写代码容易写错。 class Solution: def isValid(self, s: str) -> bool: a_stack = list() for i in s: if i == '(': a_stack.append(')') el
阅读全文
摘要:232.用栈实现队列 class MyQueue: def __init__(self): self.stack_in = list() self.stack_out = list() def push(self, x: int) -> None: self.stack_in.append(x) d
阅读全文