代码拉取完成,页面将自动刷新
https://leetcode.cn/problems/convert-1d-array-into-2d-array/
class Solution {
public:
vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {
vector<vector<int>> ret;
if(m*n != original.size())
return ret;
int count = 0;
vector<int> tmp;
for(auto e : original)
{
tmp.push_back(e);
count++;
if(count == n)
{
ret.push_back(tmp);
count = 0;
tmp.clear();
}
}
return ret;
}
};
--------------------------------------------------------------------------------------------
https://leetcode.cn/problems/build-an-array-with-stack-operations/
class Solution {
public:
vector<string> buildArray(vector<int>& target, int n) {
vector<string> ret;
int num = 1;
int i = 0;
while(i < target.size())
{
if(num == target[i])
{
ret.push_back("Push");
num++;
i++;
}
else
{
while(num != target[i])
{
ret.push_back("Push");
ret.push_back("Pop");
num++;
}
}
}
return ret;
}
};
--------------------------------------------------------------------------------------------
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。