1 /**
2 * Definition for binary tree
3 * struct TreeNode {
4 * int val;
5 * TreeNode *left;
6 * TreeNode *right;
7 * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
8 * };
9 */
10 class Solution {
11 public:
12 vector<vector<int> > levelOrder(TreeNode *root) {
13 // Start typing your C/C++ solution below
14 // DO NOT write int main() function
15 vector<vector<int> > r;
16 queue<TreeNode *> q,p,useless;
17
18
19
20 TreeNode * t;
21 if(root==NULL)
22 return r;
23
24 q.push(root);
25
26 while(!q.empty())
27 {
28 vector<int> v;
29 while(!q.empty())
30 {
31
32 t=q.front();
33 v.push_back(t->val);
34 q.pop();
35 if(t->left)
36 p.push(t->left);
37 if(t->right)
38 p.push(t->right);
39 }
40 q=p;
41 p=useless;
42 r.push_back(v);
43 }
44 return r;
45 }
46 };
原文链接: https://www.cnblogs.com/mengqingzhong/archive/2013/05/11/3073105.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/88049
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!