Problem statement

https://binarysearch.com/problems/Level-Order-Binary-Tree-to-Linked-List/

Solution

Use bfs traversal and make linked list on the fly.

Complexity

It is O(n) for time and space.

Code

class Solution:
    def solve(self, root):
        head = last = LLNode(None)
        d = deque([root])
        while d:
            node = d.popleft()
            last.next = LLNode(node.val)
            last = last.next
            if node.left: d.append(node.left)
            if node.right: d.append(node.right)
        return head.next