Skip to content

Commit aef9fbb

Browse files
committed
feat: adds binary_tree_inorder_traversal exercise
1 parent 74a9141 commit aef9fbb

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

binary_tree_inorder_traversal.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from typing import List, Optional
2+
3+
4+
# Definition for a binary tree node.
5+
class TreeNode:
6+
def __init__(self, val=0, left=None, right=None):
7+
self.val = val
8+
self.left = left
9+
self.right = right
10+
11+
12+
class Solution:
13+
def inorderTraversal(self, root: Optional[TreeNode]) -> List[int]:
14+
result = []
15+
16+
def inorder(root):
17+
if not root:
18+
return []
19+
20+
inorder(root.left)
21+
result.append(root.val)
22+
inorder(root.right)
23+
24+
inorder(root)
25+
26+
return result

0 commit comments

Comments
 (0)