Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Added 199-binary-tree-right-side-view Javascript Solution#362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
neetcode-gh merged 1 commit intoneetcode-gh:mainfromChrislee1996:main
Jul 6, 2022
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added 199-binary-tree-right-side-view Javascript Solution
  • Loading branch information
@Chrislee1996
Chrislee1996 committedJul 6, 2022
commit0432e3ad0cac72afb76cd5d0abcb209f6b9d2355
35 changes: 35 additions & 0 deletionsjavascript/199-binary-tree-right-side-view.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
/**
* Definition for a binary tree node.
* function TreeNode(val, left, right) {
* this.val = (val===undefined ? 0 : val)
* this.left = (left===undefined ? null : left)
* this.right = (right===undefined ? null : right)
* }
*/
/**
* @param {TreeNode} root
* @return {number[]}
*/
var rightSideView = function(root) {
let result = []
let queue = []

if (root === null) {
return []
}

queue.push(root)

while(queue.length > 0){
let length = queue.length
for (let i = 0 ; i < length ; i++) {
let node = queue.shift()
if (i === length - 1) {
result.push(node.val)
}
if (node.left !== null) queue.push(node.left)
if (node.right !== null) queue.push(node.right)
}
}
return result
};

[8]ページ先頭

©2009-2025 Movatter.jp