标签:pre back eve def turn col val 方法 binary
方法一:
1 /** 2 * Definition for a binary tree node. 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 { 14 vector<vector<int>> vec; 15 if(root == NULL) 16 return vec; 17 queue<TreeNode*> que; 18 que.push(root); 19 while(!que.empty()) 20 { 21 int size = que.size(); 22 vector<int> vec_temp; 23 while(size--) 24 { 25 TreeNode* t = que.front(); 26 vec_temp.push_back(que.front()->val); 27 que.pop(); 28 if(t->left) 29 que.push(t->left); 30 if(t->right) 31 que.push(t->right); 32 } 33 vec.push_back(vec_temp); 34 } 35 return vec; 36 } 37 };
标签:pre back eve def turn col val 方法 binary
原文地址:https://www.cnblogs.com/sunbines/p/10306560.html