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

feat: add JS solutions for 4, 739#413

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

Closed
Closed
Changes from1 commit
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
NextNext commit
feat: add JS solution to 739 Daily Temperatures
  • Loading branch information
@VasliSaidmuradov
VasliSaidmuradov committedJul 8, 2022
commitccedf87bbfe94c1563964d807253b9f61a4a4f1c
23 changes: 23 additions & 0 deletionsjavascript/739. Daily Temperatures.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
/**
* @param {number[]} temperatures
* @return {number[]}
*/

const dailyTemperatures = function(t) {
const res = new Array(t.length).fill(0)
const stack = []

for (let i = t.length - 1; i >= 0; i--) {
while (stack.length && t[i] >= stack[stack.length - 1].val) {
stack.pop()
}

if (stack.length && t[i] < stack[stack.length - 1].val) {
res[i] = stack[stack.length - 1].idx - i
}

stack.push({ idx: i, val: t[i] })
}

return res
}

[8]ページ先頭

©2009-2025 Movatter.jp