Dodomeki
Sign in

28. Same Trees

Easy

Given the roots of two binary trees, return true if they have the same structure and the same values in every position; otherwise, return false.

Example 1
Input: a = [5, 2, 8], b = [5, 2, 8]
Output: true
Example 2
Input: a = [5, 2], b = [5, null, 2]
Output: false
Constraints
  • 0 <= quantidade de nós em cada árvore <= 10^4
TreesDFS
Caso 1
a =
[5,2,8]
b =
[5,2,8]
Expected =
true
Caso 2
a =
[5,2]
b =
[5,null,2]
Expected =
false

Run checks these 2 cases. Submit runs all 6, including hidden ones.