Description:
In this problem, we are gonna check the identical structure and their values. Two tree must the same tree structurely.
Solution:
* First condition checks "both p and q are None." If it is return True.
* Second condition checks "one of p and q are None." If it is, then return False.
--> The reason is that just one of p or q done, that menas both tree don't have identical structure.
* Third condition checks "if both p node and q node are same, we step to the child node, recursively.
We are gonna see the both right child and left child of p and q.
When we reach out the last node of p and q, their child node is None. In conclusion, we met the first condition again which is "both p and q are None."
'LeetCode ๐๏ธ > Tree' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
572. Subtree of Another Tree (0) | 2023.04.02 |
---|---|
102. Binary Tree Level Order Traversal (0) | 2023.03.21 |
124. Binary Tree Maximum Path (0) | 2023.03.20 |
226. Invert Binary Tree (0) | 2023.03.20 |
104. Maximum Depth of Binary Tree (0) | 2023.02.20 |