File tree 2 files changed +35
-0
lines changed
2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 41
41
83|[ Remove Duplicates from Sorted List] ( ./0083-remove-duplicates-from-sorted-list.js ) |Easy|
42
42
88|[ Merge Sorted Array] ( ./0088-merge-sorted-array.js ) |Easy|
43
43
94|[ Binary Tree Inorder Traversal] ( ./0094-binary-tree-inorder-traversal.js ) |Easy|
44
+ 101|[ Symmetric Tree] ( ./0101-symmetric-tree.js ) |Easy|
44
45
102|[ Binary Tree Level Order Traversal] ( ./0102-binary-tree-level-order-traversal.js ) |Medium|
45
46
104|[ Maximum Depth of Binary Tree] ( ./0104-maximum-depth-of-binary-tree.js ) |Easy|
46
47
111|[ Minimum Depth of Binary Tree] ( ./0111-minimum-depth-of-binary-tree.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 101. Symmetric Tree
3
+ * https://leetcode.com/problems/symmetric-tree/
4
+ * Difficulty: Easy
5
+ *
6
+ * Given the root of a binary tree, check whether it is a mirror
7
+ * of itself (i.e., symmetric around its center).
8
+ */
9
+
10
+ /**
11
+ * Definition for a binary tree node.
12
+ * function TreeNode(val, left, right) {
13
+ * this.val = (val===undefined ? 0 : val)
14
+ * this.left = (left===undefined ? null : left)
15
+ * this.right = (right===undefined ? null : right)
16
+ * }
17
+ */
18
+ /**
19
+ * @param {TreeNode } root
20
+ * @return {boolean }
21
+ */
22
+ var isSymmetric = function ( root ) {
23
+ return isBalanced ( root . left , root . right ) ;
24
+ } ;
25
+
26
+ function isBalanced ( a , b ) {
27
+ if ( ! a && ! b ) {
28
+ return true ;
29
+ }
30
+ if ( ! a || ! b ) {
31
+ return false ;
32
+ }
33
+ return a . val === b . val && isBalanced ( a . left , b . right ) && isBalanced ( a . right , b . left ) ;
34
+ }
You can’t perform that action at this time.
0 commit comments