Next Greater Element I

2017/12/7 posted in  leetcode

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;
    }
};