标签:empty otto 描述 tom roo div des 数据 struct
/* 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) { if(root == nullptr){ return {}; } vector<int> result; queue<TreeNode*> q; q.push(root); while(!q.empty()){ result.push_back(q.front() -> val); if(q.front() -> left != nullptr){ q.push(q.front() -> left); } if(q.front() -> right != nullptr){ q.push(q.front() -> right); } q.pop(); } return result; } };
标签:empty otto 描述 tom roo div des 数据 struct
原文地址:http://www.cnblogs.com/dingxiaoqiang/p/7995065.html