We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 02e8e26 commit 83a944fCopy full SHA for 83a944f
symmetric-tree/symmetric-tree.java
@@ -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