101. Symmetric Tree
My accepted Python solution to LeetCode problem 101, Symmetric Tree, running in 5ms.
- Difficulty: Easy
- Python
- Runtime 5ms
- Memory 12.6MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 5ms, memory 12.6MB, accepted 2025-12-23.
class Solution(object):
def isSymmetric(self, root):
"""
:type root: Optional[TreeNode]
:rtype: bool
"""
def isMirror(left, right):
if not left and not right:
return True
if not left or not right:
return False
return (left.val == right.val and
isMirror(left.left, right.right) and
isMirror(left.right, right.left))
return isMirror(root.left, root.right) if root else True