题目描述
blablabla
样例
blablabla
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
class Solution {
public:
vector<vector<int>> printFromTopToBottom(TreeNode* root) {
vector<vector<int>> res;
if(!root) return res;
queue<TreeNode*> q;
q.push(root);
int d = 0;
while(q.size()){
int size = q.size();
vector<int> ans;
while(size--){
auto t = q.front();
q.pop();
ans.push_back(t->val);
if(t->left) q.push(t->left);
if(t->right) q.push(t->right);
}
if(d) reverse(ans.begin(),ans.end());
d = !d;
res.push_back(ans);
}
return res;
}
};
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla