-
Notifications
You must be signed in to change notification settings - Fork 1
/
496.NextGreaterElement.cpp
40 lines (39 loc) · 1.01 KB
/
496.NextGreaterElement.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <string>
#include <queue>
using namespace std;
class Solution {
public:
vector<int> nextGreaterElement(vector<int>& findNums, vector<int>& nums) {
vector<int> res;
for(auto fb = findNums.begin();fb != findNums.end();fb++){
int x = *fb;
for(auto b = nums.begin();b!=nums.end();b++){
cout << *b;
if(*b == x){
b++;
for(;b!=nums.end();b++){
if(*b > x){
res.push_back(*b);
break;
}
}
if(b == nums.end()){
res.push_back(-1);
break;
}
else
break;
}
}
}
return res;
}
};
int main()
{
vector<int> n1 = {4,1,2};
vector<int> n2 = {1,3,4,2};
Solution s;
s.nextGreaterElement(n1,n2);
}