Python Solution with Detailed Explanation
Solution\n\nBinary Tree Level Order Traversalhttps://leetcode.com/problems/binary-tree-level-order-traversal/\n\nBreadh First Search\n Using BFS, at any instant
**Solution**\n\n**Binary Tree Level Order Traversal**https://leetcode.com/problems/binary-tree-level-order-traversal/\n\n**Breadh First Search**\n* Using BFS, at any instant only L1 and L1+1 nodes are in the queue.\n* When we start the while loop, we have L1 nodes in the queue.\n* for _ in range(len(q)) allows us to dequeue L1 nodes one by one and add L2 children one by one.\n* Time complexity: O(N). Space Complexity: O(N)\n\n```\nfrom collections import deque\nclass Solution(object):\n    def levelOrder(self, root):\n        """\n        :type root: TreeNode\n        :rtype: List[List[int]]\n        """\n        q, result = deque(), []\n        if root:\n            q.append(root)\n        while len(q):\n            level = []\n            for _ in range(len(q)):\n                x = q.popleft()\n                level.append(x.val)\n                if x.left:\n                    q.append(x.left)\n                if x.right:\n                    q.append(x.right)\n            result.append(level)\n        return result\n```\n\n**Depth First Search**\n* Use a variable to track level in the tree and use simple Pre-Order traversal\n* Add sub-lists to result as we move down the levels\n* Time Complexity: O(N)\n* Space Complexity: O(N) + O(h) for stack space\n```\nclass Solution(object):\n    def levelOrder(self, root):\n        result = []\n        self.helper(root, 0, result)\n        return result\n    \n    def helper(self, root, level, result):\n        if root is None:\n            return\n        if len(result) <= level:\n            result.append([])\n        result[level].append(root.val)\n        self.helper(root.left, level+1, result)\n        self.helper(root.right, level+1, result)\n```
[]