Solution
C++ []\nclass Solution {\npublic:\n    vector<vector<int>> levelOrder(TreeNode* root) {\n        vector<vector<int>>ans;\n        if(root==NULL)return ans;\n   
```C++ []\nclass Solution {\npublic:\n    vector<vector<int>> levelOrder(TreeNode* root) {\n        vector<vector<int>>ans;\n        if(root==NULL)return ans;\n        queue<TreeNode*>q;\n        q.push(root);\n        while(!q.empty()){\n            int s=q.size();\n            vector<int>v;\n            for(int i=0;i<s;i++){\n                TreeNode *node=q.front();\n                q.pop();\n                if(node->left!=NULL)q.push(node->left);\n                if(node->right!=NULL)q.push(node->right);\n                v.push_back(node->val);\n            }\n            ans.push_back(v);\n        }\n        return ans;\n    }\n};\n```\n\n```Python3 []\nfrom collections import deque\nclass Solution:\n    def levelOrder(self, root: Optional[TreeNode]) -> List[List[int]]:\n        if not root:\n            return []\n        Q = deque([root])\n        levels = [[root.val]]\n        temp = deque()\n\n        while Q:\n            node = Q.popleft()\n            if node.left: temp.append(node.left)\n            if node.right: temp.append(node.right)\n            \n            if not Q:\n                if temp:\n                    levels.append([n.val for n in temp])\n                Q = temp\n                temp = deque()\n\n        return levels\n```\n\n```Java []\nclass Solution {\n    public List<List<Integer>> levelOrder(TreeNode root) \n    {\n        List<List<Integer>>al=new ArrayList<>();\n        pre(root,0,al);\n        return al;\n    }\n    public static void pre(TreeNode root,int l,List<List<Integer>>al)\n    {\n        if(root==null)\n            return;\n        if(al.size()==l)\n        {\n            List<Integer>li=new ArrayList<>();\n            li.add(root.val);\n            al.add(li);\n        }\n        else\n            al.get(l).add(root.val);\n        pre(root.left,l+1,al);\n        pre(root.right,l+1,al);\n    } \n}\n```\n
['C++', 'Java', 'Python3']