[Python] Simple bfs, explained
What is level in our binary tree? It is set of nodes, for which distance between root and these nodes are constant. And if we talk about distances, it can be a 
What is level in our binary tree? It is set of nodes, for which distance between root and these nodes are constant. And if we talk about distances, it can be a good idea to use `bfs`.\n\n1. We put our `root` into queue, now we have level `0` in our queue.\n2. On each step extract all nodes from queue and put their children to to opposite end of queue. In this way we will have full level in the end of each step and our queue will be filled with nodes from the next level.\n3. In the end we just return `result`.\n\n#### Complexity\nTime complexity is `O(n)`: we perform one `bfs` on our tree. Space complexity is also `O(n)`, because we have answer of this size.\n\n#### Code\n```python\nclass Solution:\n    def levelOrder(self, root):\n        if not root: return []\n        queue, result = deque([root]), []\n        \n        while queue:\n            level = []\n            for i in range(len(queue)):\n                node = queue.popleft()\n                level.append(node.val)\n                if node.left:  queue.append(node.left)\n                if node.right: queue.append(node.right)\n            result.append(level)\n        return result\n```\n\nIf you have any questions, feel free to ask. If you like solution and explanations, please **Upvote!**
['Breadth-First Search']