层次遍历
#include <vector>
class Solution {
public:
vector<int> PrintFromTopToBottom(TreeNode* root) {
if(root == nullptr) return {};
std::queue<TreeNode*> Q;
std::vector<int> res;
Q.push(root);
while(!Q.empty()){
TreeNode* curP = Q.front();
Q.pop();
res.push_back(curP->val);
if(curP->left) Q.push(curP->left);
if(curP->right) Q.push(curP->right);
}
return res;
}
};