Python 代码
class Solution:
def convert(self, root):
if not root:return
res =[]
self.dfs(root,res)
for i,v in enumerate(res[:-1]):
v.right = res[i + 1]
res[i + 1].left = v
return res[0]
def dfs(self,root,res):
if not root:return
self.dfs(root.left,res)
res.append(root)
self.dfs(root.right,res)