class Solution {
public:
vector<string> buildArray(vector<int>& target, int n) {
//对于每一个[0..n]中的数字,如果,它存在于target之中那么就push_back一个Push
//否则push_back一个pop_back
set<int>obj;
for(int i=0;i<target.size();i++)
{
obj.insert(target[i]);
}
vector<string>res;
for(int i=1;i<=*max_element(target.begin(),target.end());i++)
{
if(obj.count(i)==0)
{
res.push_back("Push");
res.push_back("Pop");
}
else
{
res.push_back("Push");
}
}
return res;
}
};
LeetCode:1441. 用栈操作构建数组
最新推荐文章于 2022-10-15 09:45:42 发布