Invert Binary Tree LeetCode solution in Python

1
# Runtime: 7 ms (Top 98.3%) | Memory: 13.26 MB (Top 67.3%)
2

3

4
class Solution(object):
5
def invertTree(self, root):
6
# Base case...
7
if root == None:
8
return root
9
# swapping process...
10
root.left, root.right = root.right, root.left
11
# Call the function recursively for the left subtree...
12
self.invertTree(root.left)
13
# Call the function recursively for the right subtree...
14
self.invertTree(root.right)
15
return root # Return the root...

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0