标签:
思路:广搜即可
class Solution {
public:
vector<vector<int> > levelOrder(TreeNode *root) {
vector<vector<int> > resVec;
if (!root)
return resVec;
queue<TreeNode*> nodeQue;
nodeQue.push(root);
while (!nodeQue.empty())
{
vector<int> subVec;
int qSize = nodeQue.size();
for (size_t i = 0; i < qSize; i++)
{
if (nodeQue.front()->left)
nodeQue.push(nodeQue.front()->left);
if (nodeQue.front()->right)
nodeQue.push(nodeQue.front()->right);
subVec.push_back(nodeQue.front()->val);
nodeQue.pop();
}
resVec.push_back(subVec);
}
return resVec;
}
};
Binary Tree Level Order Traversal
标签:
原文地址:http://www.cnblogs.com/flyjameschen/p/fab978d81dfb209c08ab3a42af9d0823.html