标签:tle queue off vector class 打印 cto int sub
/* 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> out; if(root==NULL) return out; queue<TreeNode*> Q; //要注意加* Q.push(root); while(!Q.empty()){ TreeNode* p = Q.front(); out.push_back(p->val); Q.pop(); if(p->left!=NULL) Q.push(p->left); if(p->right!=NULL) Q.push(p->right); } return out; } };
标签:tle queue off vector class 打印 cto int sub
原文地址:https://www.cnblogs.com/loyolh/p/12343084.html