Commented Code. Easy to understand! 📝
Complexity\n- Time complexity:\nThe time complexity of this solution is linear, O(n) , where n  is the number of nodes, because every node is visited and printe
# Complexity\n- Time complexity:\nThe time complexity of this solution is linear, $$O(n)$$ , where n  is the number of nodes, because every node is visited and printed only once.\n\n- Space complexity:\nThe space complexity of this solution is linear, $$O(n)$$ , since the algorithm instantiates queues that take up space of up to  $$n / 2$$ nodes. This is because the maximum queue size occurs at the level of the leaf nodes of a balanced binary tree.\n\n# Code\n```\nclass Solution {\n    public List<List<Integer>> levelOrder(TreeNode root) {\n        // Check if the root is null\n        if (root == null) {\n            return new ArrayList<>();  // Return an empty list if the tree is empty\n        }\n\n        Queue<TreeNode> queue = new ArrayDeque<TreeNode>();\n        List<List<Integer>> traversal = new ArrayList<>();\n\n        queue.add(root);  // Add the root node to the queue\n\n        // Start level-order traversal\n        while (!queue.isEmpty()) {\n            List<Integer> currLevel = new ArrayList<>();\n            int currSize = queue.size();  // Get the number of nodes at the current level\n\n            // Process all nodes at the current level\n            for (int i = 0; i < currSize; i++) {\n                TreeNode currNode = queue.poll();  // Get the next node\n\n                // Add its value to the current level\'s list\n                currLevel.add(currNode.val);\n\n                // Add the children to the queue if they are not null\n                if (currNode.left != null) {\n                    queue.add(currNode.left);\n                }\n                if (currNode.right != null) {\n                    queue.add(currNode.right);\n                }\n            }\n\n            // Add the current level\'s list to the result\n            traversal.add(currLevel);\n        }\n\n        return traversal;\n    }\n}\n```
['Tree', 'Breadth-First Search', 'Binary Tree', 'C++', 'Java']