class Solution:
def flatten(self, root):
"""
:type root: TreeNode
:rtype: void Do not return anything, modify root in-place instead.
"""
if not root: return
if root.left:
self.flatten(root.left)
if root.right:
self.flatten(root.right)
l=root.left
if not l: return
r=root.right
pl=l
while l and l.right:
l=l.right
l.right=r
root.right=pl
root.left=None
python leetcode 114. Flatten Binary Tree to Linked List
最新推荐文章于 2024-01-17 15:25:50 发布