JAVA || Easy Clean Solution || 100% Faster Code
Approach\nUse a regular binary tree BFS, but the difference is to keep track of the levels, so we need to have a list of all nodes at each level.\n\nHint: We ca
# Approach\nUse a regular binary tree BFS, but the difference is to keep track of the levels, so we need to have a list of all nodes at each level.\n\nHint: We can do this by adding a simple loop that run as much as their is nodes in the queue, \n\nPlease Upvote if this was helpful\n\n# Code\n```\npublic List<List<Integer>> levelOrder(TreeNode root) {\n    Queue<TreeNode> q = new LinkedList();\n    List<List<Integer>> res = new LinkedList();\n    \n    if(root == null) return res;\n    \n    q.offer(root);\n    while(!q.isEmpty()){\n        int lvl = q.size();\n        List<Integer> temp = new LinkedList();\n        //add all nodes in queue to temp list\n        for(int i = 0; i < lvl; i++) {\n            TreeNode curr = q.peek();\n            if(curr.left != null) q.offer(curr.left);\n            if(curr.right != null) q.offer(curr.right);\n            temp.add(q.poll().val);\n        }\n        res.add(temp);\n    }\n    return res;\n}\n```
['Breadth-First Search', 'Queue', 'Java']