标签:
Flatten Binary Tree to Linked List
问题:
Given a binary tree, flatten it to a linked list in-place.
思路:
前序pre-order遍历+prenode
我的代码:
public class Solution { public void flatten(TreeNode root) { if(root == null) return; if(pre != null) { pre.left = null; pre.right = root; } pre = root; TreeNode left = root.left; TreeNode right = root.right; flatten(left); flatten(right); } TreeNode pre = null; }
学习之处:
Flatten Binary Tree to Linked List
标签:
原文地址:http://www.cnblogs.com/sunshisonghit/p/4375440.html