For this LeetCode problem why I'm getting this error
vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {
stack<int>s;
map<int,int>nge;
for (int i=nums2.size()-1;i>=0;i--) {
if(s.top()>nums2[i]) {
nge[nums2[i]]=s.top();
}
else {
while(!s.empty() && s.top()<=nums2[i]) s.pop();
if(!s.empty()) nge[nums2[i]]=s.top();
else nge[nums2[i]]=-1;
}
s.push(nums2[i]);
}
vector<int>ans;
for (int i=0;i<nums1.size();i++) {
int temp=nge[nums1[i]];
ans.push_back(temp);
}
return ans;
}
Thanks for advance in solution!, Thank you very much for advance in solution!, Tysm for advance in solution!
Aucun commentaire:
Enregistrer un commentaire