Skip to content

Instantly share code, notes, and snippets.

@Cee
Created May 14, 2014 02:16
Show Gist options
  • Save Cee/e49c56250bc314648818 to your computer and use it in GitHub Desktop.
Save Cee/e49c56250bc314648818 to your computer and use it in GitHub Desktop.
/**
* 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;
if ((p != null) && (q == null)) return false;
if ((p == null) && (q != null)) return false;
if (p.val == q.val) {
return (true && isSameTree(p.left, q.left) && isSameTree(p.right, q.right));
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment