代码如下:
This file contains 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 binary tree | |
* public class TreeNode { | |
* int val; | |
* TreeNode left; | |
* TreeNode right; | |
* TreeNode(int x) { val = x; } | |
* } | |
*/ | |
public class Solution { | |
public boolean isSameTree(TreeNode p, TreeNode q) { | |
if (p == null && q == null) | |
return true; | |
else if (p != null && q != null) { | |
if (p.val == q.val) | |
return isSameTree(p.left, q.left) && isSameTree(p.right, q.right); | |
else | |
return false; | |
} else | |
return false; | |
} | |
} |
No comments:
Post a Comment