We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c9c25a2 commit fda6438Copy full SHA for fda6438
construct-binary-tree-from-preorder-and-inorder-traversal/HodaeSsi.py
@@ -0,0 +1,12 @@
1
+class Solution:
2
+ def buildTree(self, preorder: List[int], inorder: List[int]) -> Optional[TreeNode]:
3
+ if inorder == []:
4
+ return None
5
+
6
+ mid = preorder.pop(0)
7
+ midIdx = inorder.index(mid)
8
+ left = self.buildTree(preorder, inorder[:midIdx])
9
+ right = self.buildTree(preorder, inorder[midIdx + 1:])
10
11
+ return TreeNode(mid, left, right)
12
0 commit comments