-
Notifications
You must be signed in to change notification settings - Fork 19
/
answer.py
25 lines (21 loc) · 765 Bytes
/
answer.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
#!/usr/bin/env python3
#-------------------------------------------------------------------------------
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def isSymmetric(self, root):
"""
:type root: TreeNode
:rtype: bool
"""
return self.isEqual(root, root)
def isEqual(self, n1, n2):
if not n1 and not n2: return True
if not n1 or not n2: return False
return (n1.val == n2.val) and self.isEqual(n1.right, n2.left) and self.isEqual(n1.left, n2.right)
#-------------------------------------------------------------------------------
# Testing