摘要:
层序遍历 1、迭代法,使用队列 class Solution: def levelOrder(self, root: Optional[TreeNode]) -> List[List[int]]: res = [] if root is None: return res queue = [root] 阅读全文
摘要:
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 阅读全文
摘要:
实现 strStr() kmp 算法 一、暴力解法 class Solution: def strStr(self, haystack: str, needle: str) -> int: m, n = len(haystack), len(needle) for i in range(m): if 阅读全文