广度搜索(按每行分割开)
class Solution {
public:
vector<vector<int>> levelOrder(TreeNode* root) {
vector<vector<int>>out;
if(root==NULL)return out;
queue<TreeNode*>temp;
temp.push(root);
while(!temp.empty()){
int n=temp.size();
vector<int>B;
for(int i=0;i<n;i++){
TreeNode* no=temp.front();
temp.pop();
B.push_back(no->val);
if(no->left)temp.push(no->left);
if(no->right)temp.push(no->right);
}
out.push_back(B);
}
return out;
}
};