# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def flatten(self, root: Optional[TreeNode]) -> None:
"""
Do not return anything, modify root in-place instead.
"""
if not root:
return None
self.flatten(root.left)
self.flatten(root.right)
temp=root.right
root.right=root.left
root.left=None
while root.right:
root=root.right
root.right=temp
Leetcode-114.二叉树展开为链表(Python)
最新推荐文章于 2024-09-12 11:03:37 发布