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 5160bb7 commit 296904dCopy full SHA for 296904d
503-next-greater-element-II.js
@@ -1,3 +1,28 @@
1
+/**
2
+ * @param {number[]} nums
3
+ * @return {number[]}
4
+ */
5
+const nextGreaterElements = function(nums) {
6
+ const arr = []
7
+ const n = nums.length
8
+ const res = Array(n).fill(-1)
9
+ nums.push(...nums)
10
+ const stk = []
11
+ for(let i = 0; i < 2 * n; i++) {
12
+ const e = nums[i]
13
+ while(stk.length && nums[stk.at(-1)] < e) {
14
+ const idx = stk.pop()
15
+ res[idx] = e
16
+ }
17
+ if(i < n) stk.push(i)
18
19
+
20
+ return res
21
+};
22
23
+// another
24
25
26
/**
27
* @param {number[]} nums
28
* @return {number[]}
0 commit comments