Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

496. Next Greater Element I.cpp

class Solution {
public:
    vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {
        vector<int> res;
        for(int i=0;i<nums1.size();i++)
        {
            for(int j=0;j<nums2.size();j++)
            {
                if(nums1[i]==nums2[j])
                {
                    int k;
                    for(k=j+1;k<nums2.size();k++)
                    {
                        if(nums2[k]>nums2[j])
                        {
                            res.push_back(nums2[k]);
                            break;
                        }
                    }
                    if(k==nums2.size())
                        res.push_back(-1);
                    
                    break;
                }
                 
            }
        }
     
        return res;
    }
};
Source by www.codegrepper.com #
 
PREVIOUS NEXT
Tagged: #Next #Greater #Element
ADD COMMENT
Topic
Name
2+5 =