class Solution {
public:
vector<int> nextGreaterElement(vector<int>& findNums, vector<int>& nums) {
vector<int> res;
for(auto num1:findNums){
for (int i = 0; i<nums.size(); i++) {
int log = 0;
if (nums[i]==num1) {
for (int j = i; j<nums.size(); j++) {
if (nums[j]>num1) {
res.push_back(nums[j]);
log = 1;
break;
}
}
if (log == 0) res.push_back(-1);
break;
}
}
}
return res;
}
};
Next Greater Element I
Copyright © 2017 Powered by LZH, Theme used GitHub CSS.