Same Tree

Read the lesson → understand the pattern → then code. Tutor works offline (built-in teacher); optional Cursor/Gemini keys upgrade chat quality.

Topic refresher: Binary Trees — Recursion Native

Answer for a node from left + right children.

int maxDepth(TreeNode* root) {
    if (!root) return 0;
    return 1 + max(maxDepth(root->left), maxDepth(root->right));
}
LeetCode
3/3
EasyBinary TreesLeetCode #100

Same Tree

Both null → true. One null → false. Values equal && recurse sides.

Examples

Example 1

Input

1 2 3
1 2 3

Output

true
Example 2

Input

1 2
1 null 2

Output

false

Stuck? Take a nudge

C++17