Java Solution using DFS
Nothing special. Just wanna provide a different way from BFS.\n\n    public List> levelOrder(TreeNode root) {\n            List> res = new ArrayList>();\n      
Nothing special. Just wanna provide a different way from BFS.\n\n    public List<List<Integer>> levelOrder(TreeNode root) {\n            List<List<Integer>> res = new ArrayList<List<Integer>>();\n            levelHelper(res, root, 0);\n            return res;\n        }\n        \n        public void levelHelper(List<List<Integer>> res, TreeNode root, int height) {\n            if (root == null) return;\n            if (height >= res.size()) {\n                res.add(new LinkedList<Integer>());\n            }\n            res.get(height).add(root.val);\n            levelHelper(res, root.left, height+1);\n            levelHelper(res, root.right, height+1);\n        }
[]