Skip to content

Instantly share code, notes, and snippets.

@kapilgupta101292
Last active May 1, 2019 02:27
Show Gist options
  • Select an option

  • Save kapilgupta101292/c9f6ecb3a7f327c477f66c1bcfc0402f to your computer and use it in GitHub Desktop.

Select an option

Save kapilgupta101292/c9f6ecb3a7f327c477f66c1bcfc0402f to your computer and use it in GitHub Desktop.
/**
* 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