上一页 1 ··· 5 6 7 8 9 10 11 12 13 14 下一页
摘要: 使用迭代: class Solution: def hasPathSum(self, root: Optional[TreeNode], targetSum: int) -> bool: # 如果根节点为空,直接返回False if not root: return False # 使用栈来进行迭代 阅读全文
posted @ 2024-02-22 15:00 Junior_bond 阅读(8) 评论(0) 推荐(0)
摘要: 插入排序 def insrt_sort(aimlist): n=len(aimlist) for cur in range(1,n): i=cur while i>0: if aimlist[i]<aimlist[i-1]: aimlist[i],aimlist[i-1]=aimlist[i-1], 阅读全文
posted @ 2024-02-21 11:54 Junior_bond 阅读(21) 评论(0) 推荐(0)
摘要: 冒泡排序: def bible_sort(aimlist): n=len(aimlist) j=len(aimlist) while j>0: for i in range(n-1): if aimlist[i]>aimlist[i+1]: aimlist[i],aimlist[i+1]=aimli 阅读全文
posted @ 2024-02-21 10:17 Junior_bond 阅读(16) 评论(0) 推荐(0)
摘要: 栈的实现: class Stack(object): def __init__(self): self.__list=[] def push(self,item): self.__list.append(item) def pop(self): return self.__list.pop() de 阅读全文
posted @ 2024-02-21 10:14 Junior_bond 阅读(7) 评论(0) 推荐(0)
摘要: 自己写的: # 二叉树节点的定义 class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right class Solution: 阅读全文
posted @ 2024-02-21 10:11 Junior_bond 阅读(7) 评论(0) 推荐(0)
摘要: 对称二叉树走不通 201 / 228 个通过的测试用例 class Solution: def isBalanced(self, root: Optional[TreeNode]) -> bool: queue=[root] if not root: return True if not root. 阅读全文
posted @ 2024-02-20 11:49 Junior_bond 阅读(7) 评论(0) 推荐(0)
摘要: 递归: class Solution: def process(self,left,right,nums): if left>right: return None mid=left+(right-left)//2 midnode=TreeNode(nums[mid]) midnode.left=se 阅读全文
posted @ 2024-02-19 13:00 Junior_bond 阅读(13) 评论(0) 推荐(0)
摘要: 迭代法: class Solution: def maxDepth(self, root: Optional[TreeNode]) -> int: queue=[root] if not root: return 0 depth=0 while queue: level_len = len(queu 阅读全文
posted @ 2024-02-18 16:31 Junior_bond 阅读(11) 评论(0) 推荐(0)
摘要: 迭代法: # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # 阅读全文
posted @ 2024-02-05 18:24 Junior_bond 阅读(7) 评论(0) 推荐(0)
摘要: 自己写的有问题 即使先序+中序的结果一样 也不能确定同一棵树 # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = 阅读全文
posted @ 2024-02-04 15:00 Junior_bond 阅读(8) 评论(0) 推荐(0)
上一页 1 ··· 5 6 7 8 9 10 11 12 13 14 下一页