| 56 | # self.next = None |
| 57 | |
| 58 | class Solution: |
| 59 | # @param root, a tree link node |
| 60 | # @return nothing |
| 61 | def connect(self, root): |
| 62 | if not root: |
| 63 | return |
| 64 | |
| 65 | current = [root] |
| 66 | next_nodes = [] |
| 67 | |
| 68 | while current or next_nodes: |
| 69 | for i in current: |
| 70 | if i.left: |
| 71 | if next_nodes: |
| 72 | next_nodes[-1].next = i.left |
| 73 | |
| 74 | next_nodes.append(i.left) |
| 75 | if i.right: |
| 76 | if next_nodes: |
| 77 | next_nodes[-1].next = i.right |
| 78 | |
| 79 | next_nodes.append(i.right) |
| 80 | |
| 81 | current = next_nodes |
| 82 | next_nodes = [] |
| 83 |
nothing calls this directly
no outgoing calls
no test coverage detected