22 · Tree Recursion

#101 Symmetric Tree

Easysolve on LeetCode ↗

frequently reported atLinkedInBloombergMicrosoftAmazonGoogleMeta

the problem

In plain words

Check whether a binary tree is the mirror image of itself: fold it down the middle and the left half must land exactly on the right half, values included. Return true or false.

in root = [1,2,2,3,4,4,3]

out true

The left half 2 → (3, 4) mirrors the right half 2 → (4, 3).

in root = [1,2,2,null,3,null,3]

out false

Both 3s hang on the right side of their parents, so the halves don't mirror.

  • 1 ≤ number of nodes ≤ 1000
  • -100 ≤ Node.val ≤ 100

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

LeetCode-style: complete the class. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #100
      Same Tree
      Easyin Tree Recursion
    2. #226
      Invert Binary Tree
      Easyin Tree Recursion
    3. #572
      Subtree of Another Tree
      Easyin Tree Recursion