LeetCode:496. 下一个更大元素 I

class Solution {

public:

vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {

vector<int>greater=nextGreaterElement(nums2);

unordered_map<int,int>greaterMap;

for(int i=0;i<nums2.size();i++){

greaterMapnums2\[i]=greateri;

}

vector<int>res(nums1.size());

for(int i=0;i<nums1.size();i++){

resi=greaterMapnums1\[i];

}

return res;

}

vector<int> nextGreaterElement(vector<int>& nums){

int n=nums.size();

vector<int>res(n);

stack<int> s;

for(int i=n-1;i>=0;i--){

while(!s.empty()&&s.top()<=numsi){

s.pop();

}

resi=s.empty()?-1:s.top();

s.push(numsi);

}

return res;

}

};

相关推荐
开开心心就好2 分钟前
电脑禁止自动休眠工具,还能按负载定时
算法·智能手机·pdf·电脑·word·音视频·lua
拾码录1 小时前
深入理解链表:动态数据结构的基石
c语言·数据结构·链表
geovindu12 小时前
python:DecisionTree
开发语言·后端·python·算法
ShineWinsu12 小时前
对于Qt:事件的解析
c++·qt·面试·笔试·gui·客户端·事件
geovindu13 小时前
python: Decision Tree Regressor
开发语言·后端·python·算法·决策树
闻缺陷则喜何志丹14 小时前
【数论】P10136 [USACO24JAN] Cowlendar S|普及+
c++·数学·数论·洛谷
apcipot_rain15 小时前
某游戏公司C++游开实习 机试复盘
c++·游戏
AllData公司负责人15 小时前
实战二:AllData大模型与AI数据底座-数据传输平台-DBSyncer,搭建 Http 接口同步至 Doris,API 业务数据自动拉取入数仓
大数据·数据库·数据仓库·人工智能·算法·http·doris
武子康16 小时前
火系被选七成,就应该削弱吗?
人工智能·算法·机器学习