# 二叉树展开为链表

给你二叉树的根结点 root ,请你将它展开为一个单链表:

 

示例 1:

输入:root = [1,2,5,3,4,null,6]
输出:[1,null,2,null,3,null,4,null,5,null,6]

示例 2:

输入:root = []
输出:[]

示例 3:

输入:root = [0]
输出:[0]

 

提示:

 

进阶:你可以使用原地算法(O(1) 额外空间)展开这棵树吗?

## template ```python class TreeNode(object): def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right class Solution: def flatten(self, root: TreeNode) -> None: """ Do not return anything, modify root in-place instead. """ while root != None: if root.left == None: root = root.right else: pre = root.left while pre.right != None: pre = pre.right pre.right = root.right root.right = root.left root.left = None root = root.right ``` ## 答案 ```python ``` ## 选项 ### A ```python ``` ### B ```python ``` ### C ```python ```