标签:
vector<vector<int>> levelOrder(TreeNode* root) {
vector<vector<int>> levelOrderTraversal;
function<void(TreeNode*, size_t)> traversal;
traversal = [&levelOrderTraversal, &traversal](TreeNode* node, size_t levelNo){
if (node == nullptr){
return;
}
if(levelNo >= levelOrderTraversal.size()){
levelOrderTraversal.push_back(vector<int>());
}
levelOrderTraversal[levelNo].push_back(node->val);
++levelNo;
traversal(node->left, levelNo);
traversal(node->right, levelNo);
};
traversal(root, 0);
return levelOrderTraversal;
}
标签:
原文地址:http://www.cnblogs.com/wuOverflow/p/4676834.html