problem
solution
postorder[r]
為根節點,並從inorder[l:r]
找到該節點,並用此節點切割,左半部為此節點的左子樹,右半部為此節點的右子樹,並遞迴下去。
1 | class Solution { |
analysis
- time complexity
O(n^2)
- space complexity
O(n^2)
n is node number
postorder[r]
為根節點,並從inorder[l:r]
找到該節點,並用此節點切割,左半部為此節點的左子樹,右半部為此節點的右子樹,並遞迴下去。
1 | class Solution { |
O(n^2)
O(n^2)
n is node number