-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path114.py
32 lines (28 loc) · 871 Bytes
/
114.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
'''
@Date: 2020-07-30 14:27:47
@LastEditors: FrankCast1e
@LastEditTime: 2020-07-30 15:03:26
@FilePath: /LeetCode/114.py
'''
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.
"""
if root == None: return None
if root.left != None:
left_tree = root.left
# 找左子树的最右侧的节点
node = left_tree
while node.right != None:
node = node.right
right_tree = root.right
node.right = right_tree
root.right = left_tree
root.left = None
self.flatten(root.right)