Skip to content

Instantly share code, notes, and snippets.

@cixuuz
Last active August 5, 2017 01:26
Show Gist options
  • Save cixuuz/b36584173c40c1d31963c27f33b9365b to your computer and use it in GitHub Desktop.
Save cixuuz/b36584173c40c1d31963c27f33b9365b to your computer and use it in GitHub Desktop.
[100 Same Tree] #leetcode
/**
* Definition for a binary tree node.
* 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;
}
return p != null && q != null && 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