Last active
May 1, 2019 02:27
-
-
Save kapilgupta101292/c9f6ecb3a7f327c477f66c1bcfc0402f to your computer and use it in GitHub Desktop.
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(int x) { val = x; } | |
| * } | |
| */ | |
| class Solution { | |
| public boolean isSameTree(TreeNode p, TreeNode q) { | |
| if(p == null && q == null){ | |
| return true; | |
| } | |
| if(p == null || q == null){ | |
| return false; | |
| } | |
| return p.val == q.val && isSameTree(p.left, q.left) && isSameTree(p.right, q.right); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment