Skip to content

Commit

Permalink
SymmetricTree.java
Browse files Browse the repository at this point in the history
  • Loading branch information
terminator123 committed Jan 18, 2016
1 parent 298312e commit 9ad5aab
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/SymmetricTree.java
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

}

}

0 comments on commit 9ad5aab

Please sign in to comment.