Skip to content

Commit 049c14c

Browse files
committed
Create 0101-symmetric-tree.java
1 parent 3d6e86e commit 049c14c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Diff for: java/0101-symmetric-tree.java

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public boolean isSymmetric(TreeNode root) {
3+
return dfs(root.left,root.right);
4+
}
5+
private boolean dfs(TreeNode a, TreeNode b){
6+
if(a == null && b == null ){
7+
return true;
8+
}
9+
if(a == null || b == null ){
10+
return false;
11+
}else if(a.val != b.val){
12+
return false;
13+
}else{ // normal path
14+
return dfs(a.left,b.right) && dfs(a.right,b.left) ;
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)