Problem
Given two binary trees, write a function to check if they are the same or not.
Two binary trees are considered the same if they are structurally identical and the nodes have the same value.
Examples
1 | Input: 1 1 |
1 | Input: 1 1 |
1 | Input: 1 1 |
Solution1
Method: Recursive Depth First Search
Time Complexity:
Space Complexity:
1 | # Definition for a binary tree node. |
Solution2
Method: Iterative Depth First Search
Time Complexity:
Space Complexity:
1 | # Definition for a binary tree node. |