Skip to content

Commit bf5a93d

Browse files
Merge pull request #3426 from adhamahmad/a
Create 0101-symmetric-tree.java
2 parents e650410 + 049c14c commit bf5a93d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

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)