Symmetric Tree
Check if a binary tree is a mirror of itself
Python Code
7class Solution:● def isSymmetric(self, root) -> bool:9 if not root:......12 13 def isMirror(self, left, right) -> bool:14 # Both null - symmetric at this position15 if not left and not right:16 return True17 # One null, other not - asymmetric......20 # Values must match21 if left.val != right.val:22 return False23 # Check outer pair and inner pair24 outer = self.isMirror(left.left, right.right)25 if not outer:26 return False27 inner = self.isMirror(left.right, right.left)28 return outer and innerCurrent Line (8): Function Entry
Tree Structure
Unvisited
Entering Frame
Exploring Left
Recording Value
Exploring Right
Done ✓
Mirror Check Progress
Recursion Stack
Stack is empty. Click Next to begin!
Step Explanation
Line 8 in mirror check
Mirror check in progress.
- > Current operation: Waiting to start
- > Progress: 0/21