Symmetric Tree

Check if a binary tree is a mirror of itself

Read Here
Step0/21
Comparing-
ResultChecking...
Back To Trees List

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 position
15 if not left and not right:
16 return True
17 # One null, other not - asymmetric
......
20 # Values must match
21 if left.val != right.val:
22 return False
23 # Check outer pair and inner pair
24 outer = self.isMirror(left.left, right.right)
25 if not outer:
26 return False
27 inner = self.isMirror(left.right, right.left)
28 return outer and inner
Current Line (8): Function Entry

Tree Structure

Unvisited
Entering Frame
Exploring Left
Recording Value
Exploring Right
Done ✓
1234

Mirror Check Progress

Current Node

-

Phase

Check Symmetry

Status: Checking...
Step 1: CHECK IF TREE IS SYMMETRIC

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