[Java] Runtime: 0ms, faster than 100% || Memory usage less than 93.58%
\nclass Solution {\n    public List<List<Integer>> levelOrder(TreeNode root) {\n        List<List<Integer>> result = new ArrayList<>();\n        if (root == nul
```\nclass Solution {\n    public List<List<Integer>> levelOrder(TreeNode root) {\n        List<List<Integer>> result = new ArrayList<>();\n        if (root == null) return result;\n        Queue<TreeNode> queue = new LinkedList<>();\n        queue.add(root);\n\n        while (queue.size() > 0) {\n            List<Integer> level = new ArrayList<>();\n            int levelNumber = queue.size();\n\n            for (int i = 0; i < levelNumber; i++) {\n                TreeNode node = queue.poll();\n                level.add(node.val);\n                if (node.left != null) {\n                    queue.add(node.left);\n                }\n                if (node.right != null) {\n                    queue.add(node.right);\n                }\n            }\n            result.add(level);\n        }\n        return result;\n    }\n}\n```\n\n![image](https://assets.leetcode.com/users/images/a40891c7-533b-4f0f-9f4c-3790307d55d6_1668050651.9401443.png)\n
['Java']