题解 | #从上往下打印二叉树#
从上往下打印二叉树
http://www.nowcoder.com/practice/7fe2212963db4790b57431d9ed259701
通过测试用例4/10; 骚操作。
/*
struct TreeNode {
int val;
struct TreeNode *left;
struct TreeNode *right;
TreeNode(int x) :
val(x), left(NULL), right(NULL) {
}
};*/
class Solution {
public:
vector<int> PrintFromTopToBottom(TreeNode* root) {
vector<int> v;
fun(root,v);
return v;
}
void fun(TreeNode* root,vector<int> &v){
if(root!=NULL){
v.push_back(root->val);
fun(root->left,v);
fun(root->right,v);
}
}
};