844. Check if Two Trees are Identical

EasyTreesBinary TreeDFSRecursion

Given the roots of two binary trees, determine whether they are structurally identical and have the same node values at every position. Return true or false. The input gives two level-order arrays separated by ' | '.

Input: Two level-order arrays separated by ' | '.

Output: Boolean — true or false.

Examples

Example 1
Input: [1,2,3] | [1,2,3]
Output: true
Explanation: Same structure and values.
Example 2
Input: [1,2,3] | [1,2,4]
Output: false
Explanation: Values differ.
Example 3
Input: [] | []
Output: true
Explanation: Both empty.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →