https://leetcode.com/problems/populating-next-right-pointers-in-each-node



Runtime: 68 ms, faster than 39.85% of Python3 online submissions for Populating Next Right Pointers in Each Node.
Memory Usage: 15.8 MB, less than 8.20% of Python3 online submissions for Populating Next Right Pointers in Each Node.



```python
class Solution:
    def connect(self, root: 'Node') -> 'Node':
        #5:13
        if root == None:
            return None
        
        level_list = [[root]]
        
        while 1:
            current_level = level_list[-1]
            level_list.append([])
            
            for each in current_level:
                if (each.left != None):
                    level_list[-1].append(each.left)
                if (each.right != None):
                    level_list[-1].append(each.right)
        
            if len(level_list[-1]) == 0:
                level_list = level_list[:-1]
                break
                    
        for each_level in level_list:
            for index, node in enumerate(each_level):
                if (index == len(each_level)-1):
                    node.next = None
                else:
                    node.next = each_level[index+1]
        
        return level_list[0][0]
        #5:24
```