-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathanagram.py
36 lines (25 loc) · 823 Bytes
/
anagram.py
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
32
33
34
35
36
# Comment it before submitting
class Node:
def __init__(self, value, left=None, right=None):
self.value = value
self.right = right
self.left = left
def is_mirror(root1, root2):
if root1 is None and root2 is None:
return True
if root1 is None or root2 is None:
return False
return root1.value == root2.value and is_mirror(root1.left, root2.right) and is_mirror(root1.right, root2.left)
def solution(root):
return is_mirror(root.left, root.right)
def test():
node1 = Node(3, None, None)
node2 = Node(4, None, None)
node3 = Node(4, None, None)
node4 = Node(3, None, None)
node5 = Node(2, node1, node2)
node6 = Node(2, node3, node4)
node7 = Node(1, node5, node6)
assert solution(node7)
if __name__ == "__main__":
test()