1. 对root的左子树做处理,让左子树的根节点作为,根节点的右子树,并让右子树作为左子树根节点的右子树的子树 2. 递归遍历右子树 publicvoidflatten(TreeNode root) {if(root==null){return; }if(root.left!=null){ TreeNode leftNode=root.left; TreeNode rightNode=root.
leetcode -- 109. Convert Sorted List to Binary Search Tree 题目描述 题目难度:Medium Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced binary tree is defined as a binary tr... ...
Tony's Log LeetCode "Flatten Binary Tree to Linked List" <2025年5月> 日一二三四五六 27282930123 45678910 11121314151617 18192021222324 25262728293031 1234567 Really interesting BST manipulation problem! View Code
8.7 114 Flatten Binary Tree to Linked List Question: Given a binary tree, flatten it to a linked list in-place. For example, Given 1 / \ 2 5 / \ \ 3 4 6 The flattened tree should look like: 1 \ 2 \ 3 \ 4 \ 5 \ 6 Method: put root.left to its right, and connect root....