File tree 1 file changed +35
-0
lines changed
1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ ##==================================
2
+ ## Leetcode
3
+ ## Student: Vandit Jyotindra Gajjar
4
+ ## Year: 2020
5
+ ## Problem: 226
6
+ ## Problem Name: Invert Binary Tree
7
+ ##===================================
8
+ #Invert a binary tree.
9
+ #
10
+ #Example:
11
+ #
12
+ #Input:
13
+ #
14
+ # 4
15
+ # / \
16
+ # 2 7
17
+ # / \ / \
18
+ #1 3 6 9
19
+ #Output:
20
+ #
21
+ # 4
22
+ # / \
23
+ # 7 2
24
+ # / \ / \
25
+ #9 6 3 1
26
+ class Solution :
27
+ def invertTree (self , root ):
28
+ if root is None : #Condition-check:If root is empty
29
+ return root #We return root
30
+ else : #Condition-check: Else
31
+ left = self .invertTree (root .right ) #Use recursion to invert left values
32
+ right = self .invertTree (root .left ) #Use recursion to invert right values
33
+ root .left = left #Update root.left tree to left
34
+ root .right = right #Update root.right tree to right
35
+ return root #We return root
You can’t perform that action at this time.
0 commit comments