author: Blankj blog : http://blankj.com time : 2017/10/08 desc :
| 12 | * </pre> |
| 13 | */ |
| 14 | public class Solution { |
| 15 | public boolean isSameTree(TreeNode p, TreeNode q) { |
| 16 | if (p == null || q == null) return p == q; |
| 17 | if (p.val != q.val) return false; |
| 18 | return isSameTree(p.left, q.left) && isSameTree(p.right, q.right); |
| 19 | } |
| 20 | |
| 21 | public static void main(String[] args) { |
| 22 | Solution solution = new Solution(); |
| 23 | System.out.println(solution.isSameTree( |
| 24 | TreeNode.createTestData("[1,2,2,null,3,null,3]"), |
| 25 | TreeNode.createTestData("[1,2,2,null,3,null,3]")) |
| 26 | ); |
| 27 | System.out.println(solution.isSameTree( |
| 28 | TreeNode.createTestData("[1,2,2,null,3,null,3]"), |
| 29 | TreeNode.createTestData("[1,2,2,null,3,null,null]")) |
| 30 | ); |
| 31 | } |
| 32 | } |
nothing calls this directly
no outgoing calls
no test coverage detected