Skip to content

Commit 8a424e4

Browse files
committed
2020-08-01
1 parent 8d515ec commit 8a424e4

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed
Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
# Definition for a binary tree node.
22
# class TreeNode(object):
3-
# def __init__(self, x):
4-
# self.val = x
5-
# self.left = None
6-
# self.right = None
7-
3+
# def __init__(self, val=0, left=None, right=None):
4+
# self.val = val
5+
# self.left = left
6+
# self.right = right
87
class Solution(object):
98
def flatten(self, root):
109
"""
1110
:type root: TreeNode
1211
:rtype: None Do not return anything, modify root in-place instead.
1312
"""
14-
if not root:
13+
if not root or (not root.left and not root.right):
1514
return root
15+
1616
self.flatten(root.left)
1717
self.flatten(root.right)
18-
19-
tmp = root.right
18+
19+
tmp = root.right
2020
root.right = root.left
21-
root.left = None
22-
23-
node = root
24-
while node.right:
25-
node = node.right
26-
node.right = tmp
27-
21+
root.left = None
22+
23+
while root and root.right:
24+
root = root.right
25+
26+
root.right = tmp

0 commit comments

Comments
 (0)