题目:
题解:
class Solution:def connect(self, root: 'Node') -> 'Node':if not root:return Nonestart = rootwhile start:self.last = Noneself.nextStart = Nonep = startwhile p:if p.left:self.handle(p.left)if p.right:self.handle(p.right)p = p.nextstart = self.nextStartreturn rootdef handle(self, p):if self.last:self.last.next = pif not self.nextStart:self.nextStart = pself.last = p