Skip to content

Commit 83a944f

Browse files
Time: 1 ms (32.51%), Space: 38.5 MB (30.22%) - LeetHub
1 parent 02e8e26 commit 83a944f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

symmetric-tree/symmetric-tree.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* public class TreeNode {
4+
* int val;
5+
* TreeNode left;
6+
* TreeNode right;
7+
* TreeNode() {}
8+
* TreeNode(int val) { this.val = val; }
9+
* TreeNode(int val, TreeNode left, TreeNode right) {
10+
* this.val = val;
11+
* this.left = left;
12+
* this.right = right;
13+
* }
14+
* }
15+
*/
16+
class Solution {
17+
public boolean isSymmetric(TreeNode root) {
18+
19+
return isMirror(root,root);
20+
21+
}
22+
23+
boolean isMirror(TreeNode t1,TreeNode t2)
24+
{
25+
if(t1==null&&t2==null)
26+
return true;
27+
if(t1==null||t2==null)
28+
return false;
29+
return (t1.val==t2.val)&&isMirror(t1.right,t2.left)&&isMirror(t1.left,t2.right);
30+
31+
}
32+
}

0 commit comments

Comments
 (0)