LeetCode—496. Next Greater Element I


//url:https://leetcode.com/problems/next-greater-element-i/description/
//先从nums中,找到每一个元素的目标值
class Solution {
public:
    vector nextGreaterElement(vector& findNums, vector& nums) {
        map compareMap;
        int size=nums.size();
        for(int i=0;inums[i]){
                    compareMap[nums[i]]=nums[j];
                    break;
                }
            }
        }
        size=findNums.size();
        vector result;
        for(int i=0;i::iterator it=compareMap.find(findNums[i]);
            if(it==compareMap.end()){
                result.push_back(-1);
            }else{
                result.push_back(it->second);
            }
        }
        return result;
    }
};


发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注