leetcode114Flatten Binary Tree to Linked List

xiaoxiao2021-02-28  107

将节点都移到右边,每个节点本身作为下一个节点的前节点,本身又为上一节点的后节点

# Definition for a binary tree node.

# class TreeNode(object): #     def __init__(self, x): #         self.val = x #         self.left = None #         self.right = None class Solution(object):     def flatten(self, root):         """         :type root: TreeNode         :rtype: void Do not return anything, modify root in-place instead.         """         if not root:             return None         self.flatten(root.right)         self.flatten(root.left)         root.right = self.prev         root.left = None         self.prev = root     def __init__(self):         self.prev = None
转载请注明原文地址: https://www.6miu.com/read-56338.html

最新回复(0)