-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
feat: add solutions to lc problem: No.0503. Next Greater Element II #382
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
b852482
feat: add javascript solution to lcci problem: No.02.01.Remove Duplic…
zhaocchen 3d75983
Merge remote-tracking branch 'upstream/main' into main
zhaocchen 0c068a4
Merge remote-tracking branch 'upstream/main' into main
zhaocchen 98053e2
feat: add javascript solution to lcci problem: No.02.02.Kth Node From…
zhaocchen 9ac94bf
Merge remote-tracking branch 'upstream/main' into main
zhaocchen 413ccab
feat: add javascript solution to lcci problem: No.02.03.Delete Middle…
zhaocchen e3db7cd
Merge remote-tracking branch 'upstream/main' into main
zhaocchen a0688b8
feat: add javascript solution to lcci problem: No.17.04.Missing Number
zhaocchen 251f6b3
Merge remote-tracking branch 'upstream/main' into main
zhaocchen bda8450
feat: add javascript solution to lcci problem: No.17.10.Find Majority…
zhaocchen 6c8c234
Merge remote-tracking branch 'upstream/main' into main
zhaocchen 0276f82
feat: add javascript solution to lcci problem: No.01.08.Zero Matrix
zhaocchen 5918a79
chore: add development environment start script
zhaocchen 4e8287c
Merge remote-tracking branch 'upstream/main' into main
zhaocchen 486ccb9
feat: add javascript solution to lcci problem: No.01.07.Rotate Matrix
zhaocchen 7a77e43
Merge remote-tracking branch 'upstream/main' into main
zhaocchen 5ca6c50
feat: add javascript solution to lcci problem: No.08.04.Power Set
zhaocchen 3762742
Merge branch 'main' of https://github.com/zhaocchen/doocs_leetcode in…
zhaocchen 5c42218
feat: add javascript solution to lcci problem: No.08.07.Permutation I
zhaocchen 5932609
feat: add javascript solution to lcci problem: No.08.08.Permutation II
zhaocchen b3dd1bd
Merge remote-tracking branch 'upstream/main' into main
zhaocchen 056b530
Merge remote-tracking branch 'upstream/main' into main
zhaocchen 9e920f7
feat: add javascript solution to lcci problem: No.08.09.Bracket
zhaocchen 2ea40d1
fix: fix solution to lcci problem: No.08.09.Bracket
zhaocchen 8093516
chore: add open browser of script
zhaocchen 3776e40
Merge remote-tracking branch 'upstream/main' into main
zhaocchen dfb2972
Merge branch 'main' of https://github.com/zhaocchen/doocs_leetcode in…
zhaocchen 594885f
feat: add javasript solution to lc problem: No.1855. Maximum Distance…
zhaocchen 707f8cf
Merge remote-tracking branch 'upstream/main' into main
zhaocchen 39e2d06
feat: add javascript solution to lc problem: No.0496. Next Greater El…
zhaocchen 9de33ec
Merge remote-tracking branch 'upstream/main' into main
zhaocchen 460746e
feat: add js solution to leetcode problem: No.1854. Maximum Populatio…
zhaocchen 2a93f69
Merge remote-tracking branch 'upstream/main' into main
zhaocchen ea2056e
feat: add js solution to leetcode problem: No.1094.Car Pooling
zhaocchen f6141fd
feat: add js solution to leetcode problem: No.1109.Corporate Flight B…
zhaocchen a388645
feat: add js solution to lc problem: No.0503. Next Greater Element II
zhaocchen 3b696c5
Merge remote-tracking branch 'upstream/main' into main
zhaocchen 56b94f5
Merge remote-tracking branch 'upstream/main' into main
zhaocchen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
solution/0500-0599/0503.Next Greater Element II/Solution.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @param {number[]} nums | ||
* @return {number[]} | ||
*/ | ||
var nextGreaterElements = function(nums) { | ||
let n = nums.length; | ||
let stack = []; | ||
let res = new Array(n).fill(-1); | ||
for (let i = 0; i < 2 * n; i++) { | ||
let cur = nums[i % n]; | ||
while(stack.length > 0 && nums[stack[stack.length - 1]] < cur) { | ||
res[stack.pop()] = cur; | ||
} | ||
stack.push(i % n); | ||
} | ||
return res; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.