# 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: TreeNode) -> None:
"""
Do not return anything, modify root in-place instead.
"""
def dfs(node):
if node is None:
return
raw_left, raw_right = node.left, node.right
left = dfs(raw_left)
right = dfs(raw_right)
if left is not None:
node.right = raw_left
node.left = None
node = left
if right is not None:
node.right = raw_right
node = right
return node
dfs(root)