114. Flatten Binary Tree to Linked List

class Solution {
    public void flatten(TreeNode root) {
        TreeNode cur=root, pre=null;
        while(cur!=null)
        {
            if(cur.left!=null)
            {
                pre=cur.left;
                while(pre.right!=null)
                    pre=pre.right;
                pre.right=cur.right;
                cur.right=cur.left;
                cur.left=null;
            }
            cur=cur.right;
        }
    }
}

  

posted @ 2017-09-30 04:06  Weiyu Wang  阅读(135)  评论(0编辑  收藏  举报