如何在以下程序中分配向量
how assign vector in below program?
任何人都可以告诉我这条线在下面的程序res.back().insert(end(res.back()), begin(ity->second), end(ity->second));
,如何如何我想将元素分配为使用循环的元素,而不是上述语句,但会是如果您解释以上陈述是如何分配元素的,对我有好处的我如何使用循环进行同样的操作。
任务:https://leetcode.com/problems/vertical-order-order-traversal-of-a-binary-tree/
代码:https://ideone.com/e40syr
vector<vector<int>> verticalTraversal(TreeNode* r, vector<vector<int>> res = {}) {
map<int, map<int, set<int>>> m;
dfs(r, 0, 0, m);
for (auto itx = m.begin(); itx != m.end(); ++itx) {
res.push_back(vector<int>());
for (auto ity = itx->second.begin(); ity != itx->second.end(); ++ity) {
res.back().insert(end(res.back()), begin(ity->second), end(ity->second));
}
}
return res;
}
res.back()
获得res
中的最后一个元素。
.insert(end(res.back()),
在此位置插入一些东西。
begin(ity->second), end(ity->second)
要插入的迭代范围。
);
您可以分配这是
的循环for (auto itz : ity->second)
res.back().push_back(itz);
相关文章:
- 存储在堆分配向量中的指针的免费存储
- 重新分配向量时,向量中的内存会发生什么情况
- 是否可以在堆中分配向量,但通过引用进行访问
- 如何在以下程序中分配向量
- 通过引用分配向量
- 分配向量而不复制它们
- 是否可以动态分配向量?
- 为什么从工厂函数分配向量并在循环中迭代它会导致段错误
- 如何正确分配C 向量
- 如何在C++中使用"new"动态分配向量数组?
- 如何知道何时重新分配向量的内部数组
- 预分配向量是否更有效
- 在C++中动态分配向量的安全方法是什么
- 两种不同的解分配向量的方法为什么一种不起作用?
- 将元素添加到基于范围的预分配向量中是否合法
- 使用循环重新分配向量中的字符串
- C++:动态内存分配+向量
- 尝试使用while循环取消分配向量,任务管理器显示内存使用正在增加
- 动态分配向量
- 动态分配向量(或向量的向量)