2025年10月17日
摘要:
在家毛了好幾天了,一個原因是下雨,一個原因是家里有大顯示器。 但是家里的效率奇差。 自己做飯,一日三餐得刷碗,然后吃飯得時候刷劇,吃完飯了,還很難抽離出來。 今天好了,炒白菜得時候加了兩勺我媽今年暑假在西安用白酒腌得紅辣椒末。 吃完直接給人弄得頭暈的很,睡了一覺,醒來就吃晚飯,吃完晚飯坐在電腦桌前也
閱讀全文
posted @ 2025-10-17 20:14
axuu
閱讀(7)
推薦(0)
2025年9月15日
摘要:
110. 平衡二叉樹 - 力扣(LeetCode) 二叉樹節點的深度:指從根節點到該節點的最長簡單路徑邊的條數。 二叉樹節點的高度:指從該節點到葉子節點的最長簡單路徑邊的條數。 但leetcode中強調的深度和高度很明顯是按照節點來計算的。 求深度適合用前序遍歷,而求高度適合用后序遍歷。 方法一:遞
閱讀全文
posted @ 2025-09-15 15:23
axuu
閱讀(9)
推薦(0)
2025年9月14日
摘要:
222. 完全二叉樹的節點個數 - 力扣(LeetCode) 1.迭代法,層序遍歷 class Solution: def countNodes(self, root: Optional[TreeNode]) -> int: count = 0 if not root: return count q
閱讀全文
posted @ 2025-09-14 17:25
axuu
閱讀(8)
推薦(0)
2025年9月8日
摘要:
111. 二叉樹的最小深度 - 力扣(LeetCode) 解法1:層序遍歷 # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # sel
閱讀全文
posted @ 2025-09-08 21:29
axuu
閱讀(8)
推薦(0)
2025年9月7日
摘要:
104. 二叉樹的最大深度 - 力扣(LeetCode) 解法1:迭代法,使用層序遍歷 # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None):
閱讀全文
posted @ 2025-09-07 22:07
axuu
閱讀(10)
推薦(0)
2025年9月6日
摘要:
101. 對稱二叉樹 - 力扣(LeetCode) 一、遞歸解法: 解法1 # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # sel
閱讀全文
posted @ 2025-09-06 23:00
axuu
閱讀(8)
推薦(0)
2025年9月5日
摘要:
590. N 叉樹的后序遍歷 - 力扣(LeetCode) 遞歸寫法: 寫法1:標準 DFS + extend 收集結果 class Solution: def postorder(self, root: 'Node') -> List[int]: if not root: return [] re
閱讀全文
posted @ 2025-09-05 12:23
axuu
閱讀(7)
推薦(0)
2025年9月2日
摘要:
226. 翻轉二叉樹 - 力扣(LeetCode) 方法1: 迭代法,廣度優先遍歷(層序遍歷) class Solution: def invertTree(self, root: TreeNode) -> TreeNode: if not root: return None queue = col
閱讀全文
posted @ 2025-09-02 19:27
axuu
閱讀(7)
推薦(0)
2025年8月28日
摘要:
1. 102. 二叉樹的層序遍歷 - 力扣(LeetCode) 方法一:迭代+隊列 class Solution: def levelOrder(self, root: Optional[TreeNode]) -> List[List[int]]: if not root: return [] qu
閱讀全文
posted @ 2025-08-28 23:00
axuu
閱讀(9)
推薦(0)
2025年8月20日
摘要:
方法一:空指針標記法 1. 迭代法前序遍歷 ① 空指針標記法 class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right cl
閱讀全文
posted @ 2025-08-20 18:01
axuu
閱讀(10)
推薦(0)