-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem101.py
More file actions
27 lines (23 loc) · 810 Bytes
/
problem101.py
File metadata and controls
27 lines (23 loc) · 810 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
# <---coding: utf-8--->
# @Time: 2021/12/24/23:09
# @Author = posiondy
# @Email: 1547590574@qq.com
# @Software: PyCharm
# Definition for a binary tree node.
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
class Solution:
def isSymmetric(self, root: TreeNode) -> bool:
if root is None:
return True
return self.theSame(root.right, root.left)
def theSame(self, right: TreeNode, left: TreeNode) -> bool:
if right is None and left is None:
return True
elif right is None or left is None or right.val != left.val:
return False
else:
return self.theSame(right.right, left.left) and self.theSame(right.left, left.right)