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 356e574 commit d0d4ad2Copy full SHA for d0d4ad2
199-binary-tree-right-side-view.js
@@ -0,0 +1,26 @@
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 {number[]}
11
12
+const rightSideView = function(root) {
13
+ if(root == null) return []
14
+ const queue = [root]
15
+ const res = []
16
+ while(queue.length) {
17
+ const len = queue.length
18
+ for(let i = 0; i < len; i++) {
19
+ const el = queue.shift()
20
+ if(i === len - 1) res.push(el.val)
21
+ if(el.left) queue.push(el.left)
22
+ if(el.right) queue.push(el.right)
23
+ }
24
25
+ return res
26
+};
0 commit comments