We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5503d98 commit 60c3cbbCopy full SHA for 60c3cbb
101(Recursively)_Symmetric_Tree.py
@@ -0,0 +1,30 @@
1
+# Definition for a binary tree node.
2
+# class TreeNode(object):
3
+# def __init__(self, x):
4
+# self.val = x
5
+# self.left = None
6
+# self.right = None
7
+
8
+class Solution(object):
9
10
+ def isSymmetric(self, root):
11
+ """
12
+ :type root: TreeNode
13
+ :rtype: bool
14
15
+ if root is None:
16
+ return True
17
+ else:
18
+ return self.isMirror(root.left, root.right)
19
20
+ def isMirror(self, left, right):
21
+ if None == left and None == right:
22
23
+ elif None ==left or None == right:
24
+ return False
25
+ elif left.val == right.val:
26
+ outPair = self.isMirror(left.left, right.right)
27
+ inPair = self.isMirror(left.right, right.left)
28
+ return outPair and inPair
29
30
0 commit comments