100.Same Tree
100. Same Tree
題目描述
Given the roots of two binary trees p
and q
, 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.
範例
Example 1:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Example 2:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Example 3:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Constraints:
- The number of nodes in both trees is in the range
[0, 100]
.
- -104 <=
Node.val
<= 104
解答
Javascript
Marsgoat Jan 10, 2023
Python
Ron ChenTue, Jan 10, 2023
分享討論區中發現的一行解法
c#
JimTue, Jan 10, 2023
Reference
回到題目列表