Created
September 30, 2020 04:49
-
-
Save marisnb/2b53c9913e5b933aafc56c33a58cb8e3 to your computer and use it in GitHub Desktop.
[ Leet Code ] [ Easy ] 100. Same Tree
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for a binary tree node. | |
* public class TreeNode { | |
* int val; | |
* TreeNode left; | |
* TreeNode right; | |
* TreeNode() {} | |
* TreeNode(int val) { this.val = val; } | |
* TreeNode(int val, TreeNode left, TreeNode right) { | |
* this.val = val; | |
* this.left = left; | |
* this.right = right; | |
* } | |
* } | |
*/ | |
class Solution { | |
public boolean isSameTree(TreeNode p, TreeNode q) { | |
if(null == p || null == q) | |
return p == q; | |
if(p.val != q.val) | |
return false; | |
return isSameTree(p.right, q.right) && isSameTree(p.left, q.left); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment