8000 Update README.md · abroroo/leetcode@870d134 · GitHub
[go: up one dir, main page]

Skip to content

Commit 870d134

Browse files
authored
Update README.md
1 parent da1b672 commit 870d134

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,21 @@ List is periodically updated
2323
const isSymmetric = function(root) {
2424
// tree with null root considered symmetric
2525
if (root == null) return true
26+
2627
// check if same first two nodes of the root
2728
return isSame(root.left, root.right)
2829
};
2930
3031
const isSame = (leftN, rightN) => {
3132
// if both nodes are null then tree symmetric
3233
if (leftN == null && rightN == null) return true
34+
3335
// if only one of them null, no longer symmetric
3436
if (leftN == null || rightN == null) return false
37+
3538
// if two values are not equal , not symmetric
3639
if (leftN.val !== rightN.val) return false
40+
3741
// recursivly check both outer sides of the seconf node and inner sides respectively all over the height of the tree
3842
return isSame(leftN.left, rightN.right) && isSame(leftN.right, rightN.left);
3943
}

0 commit comments

Comments
 (0)
0