"""
Problem:
https://leetcode.com/problems/symmetric-tree/description/
Solution:
https://www.youtube.com/watch?v=Mao9uzxwvmc
Description:
Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center).
"""
def is_symmetric_tree(root):
"""
:type root: TreeNode
:rtype: bool
"""
def dfs(left, right):
if not left and not right:
return True
if not left or not right:
return False
if left.val != right.val:
return False
return dfs(left.left, right.right) and dfs(left.right, right.left)
if root is None:
return True
else:
return dfs(root.left, root.right)