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 e3c1e95 commit fd89424Copy full SHA for fd89424
Stack/496.Next-Greater-Element-I/496.Next Greater Element I.cpp
@@ -7,17 +7,12 @@ class Solution {
7
8
for (int i=0; i<nums.size(); i++)
9
{
10
- if (Stack.empty() || Stack.top()>nums[i])
11
- Stack.push(nums[i]);
12
- else
+ while (!Stack.empty() && Stack.top()<nums[i])
13
14
- while (!Stack.empty() && Stack.top()<nums[i])
15
- {
16
- Map[Stack.top()]=nums[i];
17
- Stack.pop();
18
- }
19
20
+ Map[Stack.top()]=nums[i];
+ Stack.pop();
+ }
+ Stack.push(nums[i]);
21
}
22
23
vector<int>results;
0 commit comments