Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 422bb42

Browse files
committedJan 25, 2025
Add solution #199
1 parent 931d24a commit 422bb42

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
190|[Reverse Bits](./0190-reverse-bits.js)|Easy|
152152
191|[Number of 1 Bits](./0191-number-of-1-bits.js)|Easy|
153153
198|[House Robber](./0198-house-robber.js)|Medium|
154+
199|[Binary Tree Right Side View](./0199-binary-tree-right-side-view.js)|Medium|
154155
202|[Happy Number](./0202-happy-number.js)|Easy|
155156
203|[Remove Linked List Elements](./0203-remove-linked-list-elements.js)|Easy|
156157
204|[Count Primes](./0204-count-primes.js)|Medium|
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* 199. Binary Tree Right Side View
3+
* https://leetcode.com/problems/binary-tree-right-side-view/
4+
* Difficulty: Medium
5+
*
6+
* Given the root of a binary tree, imagine yourself standing on the right side of it, return the
7+
* values of the nodes you can see ordered from top to bottom.
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 {number[]}
21+
*/
22+
var rightSideView = function(root, result = [], depth = 0) {
23+
if (!root) return result;
24+
result[depth] = root.val;
25+
rightSideView(root.left, result, depth + 1);
26+
return rightSideView(root.right, result, depth + 1);
27+
};

0 commit comments

Comments
 (0)
Please sign in to comment.