@@ -0,0 +1,1055 @@
+package leetcode111_120;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0A/**Given a binary tree, flatten it to a linked list in-place.%0A * Created by eugene on 16/2/2.%0A */%0Apublic class FlattenBinaryTreeToLinkedList %7B%0A%0A    //Definition for a binary tree node.%0A    public static class TreeNode %7B%0A        int val;%0A        TreeNode left;%0A        TreeNode right;%0A        TreeNode(int x) %7B val = x; %7D%0A    %7D%0A%0A%0A    /**%0A     * dfs,%E5%85%88%E5%BA%8F%0A     * @param root%0A     */%0A    public void flatten(TreeNode root) %7B%0A        List%3CTreeNode%3E preOrderList = new ArrayList%3C%3E();%0A        preOrderTraversal(preOrderList, root);%0A        for (int i=0; i%3CpreOrderList.size()-1; i++)%7B%0A            TreeNode node = preOrderList.get(i);%0A            node.left = null;%0A            node.right = preOrderList.get(i+1);%0A        %7D%0A    %7D%0A    private void preOrderTraversal(List%3CTreeNode%3E preOrderList, TreeNode root)%7B%0A        if (root==null) return;%0A        preOrderList.add(root);%0A        preOrderTraversal(preOrderList, root.left);%0A        preOrderTraversal(preOrderList, root.right);%0A    %7D%0A%0A%7D%0A

Flatten Binary Tree to Linked List