My Java 2 solutions 1ms(dfs) & 2ms(bfs)
\u200b/**\n     * Definition for a binary tree node.\n     * public class TreeNode {\n     *     int val;\n     *     TreeNode left;\n     *     TreeNode right;
    \u200b/**\n     * Definition for a binary tree node.\n     * public class TreeNode {\n     *     int val;\n     *     TreeNode left;\n     *     TreeNode right;\n     *     TreeNode(int x) { val = x; }\n     * }\n     */\n    public class Solution {\n        public List<List<Integer>> levelOrder(TreeNode root) {\n            List<List<Integer>> res = new ArrayList<List<Integer>>();\n            if (root == null)\n                return res;\n            Queue<TreeNode> q = new LinkedList<TreeNode>();\n            q.offer(root);\n            while (!q.isEmpty()) {\n                List<Integer> tmp = new ArrayList<Integer>();\n                int size = q.size();\n                for (int i = 0; i < size; ++i) {\n                    TreeNode t = q.poll();\n                    if (t.left != null)\n                        q.offer(t.left);\n                    if (t.right != null)\n                        q.offer(t.right);\n                    tmp.add(t.val);\n                }\n                res.add(tmp);\n            }\n            return res;\n        }\n    }\n    \n    \n    /**\n     * Definition for a binary tree node.\n     * public class TreeNode {\n     *     int val;\n     *     TreeNode left;\n     *     TreeNode right;\n     *     TreeNode(int x) { val = x; }\n     * }\n     */\n    public class Solution {\n        public List<List<Integer>> levelOrder(TreeNode root) {\n            List<List<Integer>> res = new ArrayList<List<Integer>>();\n            dfs(res,root,0);\n            return res;\n        }\n        public void dfs(List<List<Integer>> list,TreeNode node,int deep){\n            if(node==null)return;\n            if(list.size()==deep)\n                list.add(new ArrayList<Integer>());\n            list.get(deep).add(node.val);\n            dfs(list, node.left, deep+1);\n            dfs(list, node.right, deep+1);    \n        }\n    }
['Java']