Tree

449. Serialize and Deserialize BST

449. Serialize and Deserialize BST 參考 297. Serialize and Deserialize

124. Binary Tree Maximum Path Sum

124. Binary Tree Maximum Path Sum 這一題是後序遍歷的經典題目,後序遍歷的精神就是先將子樹的問題全部解決,再開始處理跟節點的問題,這一題要怎麼想到的確是屬於困難的題型。

106. Construct Binary Tree from Inorder and Postorder Traversal

106. Construct Binary Tree from Inorder and Postorder Traversal postorder

94. Binary Tree Inorder Traversal

94. Binary Tree Inorder Traversal # Definition for a binary tree

286. Walls and Gates

286. Walls and Gates 這題是 BFS 廣度優先搜索的題目,DFS 應該也可以做。 我一開始的做法是把

1373. Maximum Sum BST in Binary Tree

1371. Maximum Sum BST in Binary Tree # Definition for a

222. Count Complete Tree Nodes

222. Count Complete Tree Nodes 線性搜索 # Definition for a binary

559. Maximum Depth of N-ary Tree

559. Maximum Depth of N-ary Tree """ # Definition for a Node.

261. Graph Valid Tree

DFS 搜尋的重點是,鄰居可以是 parent ,但是如果不是 parent 卻曾經造訪過,就代表這棵樹裡面有閉圈。 class Solution:

437. Path Sum III

437. Path Sum III 更難的樹的遍歷加上回溯法。 # Definition for a binary tree