标签:tle top 从上往下打印二叉树 rank nbsp empty esc practice 剑指offer
/* 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) { queue<TreeNode*> q; vector<int> result; if(root == nullptr){ return result; } q.push(root); while(!q.empty()){ TreeNode* tmp = q.front(); q.pop(); result.push_back(tmp -> val); if(tmp -> left != nullptr){ q.push(tmp -> left); } if(tmp -> right != nullptr){ q.push(tmp -> right); } } return result; } };
标签:tle top 从上往下打印二叉树 rank nbsp empty esc practice 剑指offer
原文地址:http://www.cnblogs.com/dingxiaoqiang/p/7469600.html