class Solution {
public:
        vector<vector<int> > Print(TreeNode* pRoot) {
            vector<vector<int>> res;
            if(!pRoot) return res;
            TreeNode* p=pRoot;
            queue<TreeNode*> q;
            q.push(p);
            int level=0;
            while(q.size()){
                res.push_back({});
                int n=q.size();
                for(int i=0;i<n;i++){
                    p=q.front();
                    q.pop();
                    res[level].push_back(p->val);
                    if(p->left) q.push(p->left);
                    if(p->right) q.push(p->right); 
                }
                level++;
            }
            return res;
        }
};