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 b8ef037 commit b5c5ecfCopy full SHA for b5c5ecf
problems/0503.下一个更大元素II.md
@@ -132,6 +132,26 @@ class Solution:
132
return dp
133
```
134
Go:
135
+```go
136
+func nextGreaterElements(nums []int) []int {
137
+ length := len(nums)
138
+ result := make([]int,length,length)
139
+ for i:=0;i<len(result);i++{
140
+ result[i] = -1
141
+ }
142
+ //单调递减,存储数组下标索引
143
+ stack := make([]int,0)
144
+ for i:=0;i<length*2;i++{
145
+ for len(stack)>0&&nums[i%length]>nums[stack[len(stack)-1]]{
146
+ index := stack[len(stack)-1]
147
+ stack = stack[:len(stack)-1] // pop
148
+ result[index] = nums[i%length]
149
150
+ stack = append(stack,i%length)
151
152
+ return result
153
+}
154
+```
155
156
JavaScript:
157
0 commit comments