Skip to content

Commit 6602e6c

Browse files
authored
Update 199-binary-tree-right-side-view.js
1 parent d0d4ad2 commit 6602e6c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

199-binary-tree-right-side-view.js

+18
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,21 @@ const rightSideView = function(root) {
2424
}
2525
return res
2626
};
27+
28+
// another
29+
30+
const rightSideView = function(root) {
31+
const res = []
32+
const helper = function(node, level) {
33+
if (!node) {
34+
return
35+
}
36+
if (!res[level]) {
37+
res.push(node.val)
38+
}
39+
helper(node.right, level + 1)
40+
helper(node.left, level + 1)
41+
}
42+
helper(root, 0)
43+
return res
44+
}

0 commit comments

Comments
 (0)