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 69f16be commit 619d4b8Copy full SHA for 619d4b8
101-symmetric-tree.js
@@ -0,0 +1,31 @@
1
+/**
2
+ * Definition for a binary tree node.
3
+ * function TreeNode(val) {
4
+ * this.val = val;
5
+ * this.left = this.right = null;
6
+ * }
7
+ */
8
9
+ * @param {TreeNode} root
10
+ * @return {boolean}
11
12
+const isSymmetric = function(root) {
13
+ if(root == null) return true
14
+ return compare(root.left, root.right)
15
+};
16
+
17
+function compare(l, r) {
18
+ if(l == null && r == null) return true
19
+ if( (l == null && r != null) || (l != null && r == null) ) return false
20
21
+ if(l.val === r.val) {
22
+ if(compare(l.left, r.right) !== false && compare(l.right, r.left) !== false) {
23
+ return true
24
+ } else {
25
+ return false
26
+ }
27
28
29
30
31
+}
0 commit comments