摘要:
''' 有效括号: 左括号必须以正确的顺序闭合 正确【】{} () 错误 [{]}] ''' class Solution: def is_valid(self,s): dic = {'(':')','[':']','{':'}'} stack = [] for i in s: if i in di 阅读全文
摘要:
''' 长木板长度 longer,短木板长度 shorter,一共有k长木板,可以拼成的木板长度区间是多少? ''' class Solution: def diving_board(self,shorter,longer,k): if k == 0: return [] ans = [] minl 阅读全文
摘要:
''' 1 / \ 2 3 12 + 13 = 25 ''' class TreeNode: def __init__(self,val): self.val = val self.left = None self.right = None class Solution: def sum_numbe 阅读全文
摘要:
''' 1 / \ 2 3 / \ 4 5 ''' class TreeNode: def __init__(self,val): self.val = val self.left = None self.right = None # 深度优先-先序遍历 def dfs_pre(node): if 阅读全文
摘要:
# bfs & dfs graph = { "A":["B","C"], "B":["A","C","D"], "C":["A","B","D","E"], "D":["B","C","E","F"], "E":["C&q 阅读全文