-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinvertTree
More file actions
31 lines (25 loc) · 791 Bytes
/
invertTree
File metadata and controls
31 lines (25 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Definition for a binary tree node.
class node:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
class Solution:
def invertTree(self, root):
self.isMirror(root)
return root
def isMirror(self, root):
if not root:
return
root.left, root.right = root.right, root.left
self.isMirror(root.left)
self.isMirror(root.right)
root = node(1)
#root.left = node(2)
root.right = node(2)
# root.left.left = node(1)
# root.left.right = node(3)
# root.right.left = node(6)
# root.right.right = node(9)
myVar = Solution()
myVar.invertTree(root)