/**
 * struct TreeNode {
 *	int val;
 *	struct TreeNode *left;
 *	struct TreeNode *right;
 * };
 */

class Solution {
public:
    /**
     * 
     * @param root TreeNode类 
     * @return int整型vector<vector<>>
     */
    vector<vector<int> > levelOrder(TreeNode* root) {
        vector<vector<int>>ret;
        // 判定输入
        if(!root) {
            return ret;
        }
        // queue 先进先出
        queue<TreeNode*> que;
        que.push(root);
        while(!que.empty()) {
            int size = que.size();
            vector<int>vec;
            while(size --) {
                // 取出front,将left和right推入队列中
                TreeNode *front = que.front();
                vec.push_back(front->val);
                que.pop();
                if (front->left) {
                    que.push(front->left);
                }
                if (front->right) {
                    que.push(front->right);
                }
            }
            ret.push_back(vec);
        }
        return ret;
    }
};