114

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
class Solution {
    TreeNode last = null;
    public void flatten(TreeNode root) {
        if(root == null){
            return ;
        }
        //递归过程
        flatten(root.left);
        flatten(root.right);
        //处理过程
        //The rightmost sub-tree of the root of the right subtree root into the left subtree, then the left subtree root is connected to root.right
         // while blanking the left subtree, then the pointer to root.right, to under continued 
        IF (root.left =! null ) { 
            the TreeNode pre = root.left;
             the while (pre.right =! null ) { 
                pre = pre.right; 
            } 
            pre.right = root.right; 
            root.right = the root .left; 
            root.left = null ; 
        } 

        the root = root.right; 
    } 
}

 

Guess you like

Origin www.cnblogs.com/zhaijiayu/p/11595094.html
114
114
114