广度搜索
用队列保存
class Solution {
public:
vector<int> levelOrder(TreeNode* root) {
vector<int>out;
if(root==NULL)return out;
queue<TreeNode*>temp;
temp.push(root);
while(!temp.empty()){
TreeNode*no=temp.front();
temp.pop();
out.push_back(no->val);
if(no->left)temp.push(no->left);
if(no->right)temp.push(no->right);
}
return out;
}
};