Skip to content

Commit 1abe274

Browse files
committed
Adding Recursive Solution - Problem - 94 - BT Inorder Traversal
1 parent b79c7a0 commit 1abe274

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
##==================================
2+
## Leetcode
3+
## Student: Vandit Jyotindra Gajjar
4+
## Year: 2020
5+
## Problem: 94
6+
## Problem Name: Binary Tree Inorder Traversal
7+
##===================================
8+
#
9+
#Given a binary tree, return the inorder traversal of its nodes' values.
10+
#
11+
#Example:
12+
#
13+
#Input: [1,null,2,3]
14+
# 1
15+
# \
16+
# 2
17+
# /
18+
# 3
19+
#
20+
#Output: [1,3,2]
21+
#Follow up: Recursive solution is trivial, could you do it iteratively?
22+
class Solution:
23+
def inorderTraversal(self, root):
24+
if root is None: #If root is empty
25+
return [] #Return empty list
26+
return self.inorderTraversal(root.left) + [root.val] + self.inorderTraversal(root.right) #Return inorder traversal

0 commit comments

Comments
 (0)