-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path101.py
More file actions
22 lines (16 loc) · 687 Bytes
/
Copy path101.py
File metadata and controls
22 lines (16 loc) · 687 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Definition for a binary tree node.
class TreeNode(object):
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def isSymmetric(root):
def isSameTree(left,right):
if not left and not right:
return True
if not left or not right:
return False
return left.val==right.val and isSameTree(left.left,right.right) and isSameTree(left.right,right.left)
return isSameTree(root.left,root.right)
#root=TreeNode(1,TreeNode(2,TreeNode(3),TreeNode(5)),TreeNode(2,TreeNode(3),TreeNode(5)))
#print(isSymmetric(root))