Last active
August 29, 2015 14:24
-
-
Save xynophon/ef97c99e5e53cd34151b to your computer and use it in GitHub Desktop.
LeetCode SameTree
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
| import java.util.*; | |
| public class SameTree { | |
| /** | |
| * Definition for a binary tree node. | |
| * public class TreeNode { | |
| * int val; | |
| * TreeNode left; | |
| * TreeNode right; | |
| * TreeNode(int x) { val = x; } | |
| * } | |
| */ | |
| public boolean isSameTree(TreeNode p, TreeNode q){ | |
| if(p == q){ | |
| return true; | |
| }else if(p != null && q != null) { | |
| if (p.val == q.val) { | |
| return isSameTree(p.left, q.left) && isSameTree(p.right, q.right); | |
| } | |
| }else{ | |
| return false; | |
| } | |
| return false; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment