-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
298312e
commit 9ad5aab
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package Tree; | ||
|
||
import ListNode.TreeNode; | ||
|
||
/** | ||
* | ||
* @author chenqun | ||
* Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). | ||
* | ||
*/ | ||
public class SymmetricTree { | ||
|
||
public boolean isSymmetric(TreeNode root){ | ||
if(root == null) | ||
return true; | ||
else | ||
return isSymmetricTwoTree(root.left, root.right); | ||
} | ||
//判断两棵树是不是对称的 | ||
public boolean isSymmetricTwoTree(TreeNode t1, TreeNode t2){ | ||
if(t1 == null && t2 == null) | ||
return true; | ||
if(t1 == null || t2 == null) | ||
return false; | ||
if(t1.val != t2.val){ | ||
return false; | ||
} | ||
return isSymmetricTwoTree(t1.left,t2.right) && isSymmetricTwoTree(t1.right , t2.left); | ||
} | ||
public static void main(String[] args) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
} |