File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -182,5 +182,31 @@ var nextGreaterElements = function (nums) {
182
182
return res;
183
183
};
184
184
```
185
+ TypeScript:
186
+
187
+ ``` typescript
188
+ function nextGreaterElements(nums : number []): number [] {
189
+ const length: number = nums .length ;
190
+ const stack: number [] = [];
191
+ stack .push (0 );
192
+ const resArr: number [] = new Array (length ).fill (- 1 );
193
+ for (let i = 1 ; i < length * 2 ; i ++ ) {
194
+ const index = i % length ;
195
+ let top = stack [stack .length - 1 ];
196
+ while (stack .length > 0 && nums [top ] < nums [index ]) {
197
+ resArr [top ] = nums [index ];
198
+ stack .pop ();
199
+ top = stack [stack .length - 1 ];
200
+ }
201
+ if (i < length ) {
202
+ stack .push (i );
203
+ }
204
+ }
205
+ return resArr ;
206
+ };
207
+ ```
208
+
209
+
210
+
185
211
-----------------------
186
212
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img ></div >
You can’t perform that action at this time.
0 commit comments