@@ -0,0 +1,996 @@
+/**%0A*%0A*Given a binary tree, flatten it to a linked list in-place.%0A*%0A*For example,%0A*Given%0A*%0A*         1%0A*        / %5C%0A*       2   5%0A*      / %5C   %5C%0A*     3   4   6%0A*The flattened tree should look like:%0A*   1%0A*    %5C%0A*     2%0A*      %5C%0A*       3%0A*        %5C%0A*         4%0A*          %5C%0A*           5%0A*            %5C%0A*             6%0A*/%0A%0A//---------------------solution%0A%0A/**%0A * Definition for binary tree%0A * public class TreeNode %7B%0A *     int val;%0A *     TreeNode left;%0A *     TreeNode right;%0A *     TreeNode(int x) %7B val = x; %7D%0A * %7D%0A */%0Apublic class Solution %7B%0A    %0A    private TreeNode lastVisit = null;%0A    %0A    public void flatten(TreeNode root) %7B%0A        %0A        if(root == null)%0A           return;%0A           %0A        TreeNode savedRight = root.right;%0A        if(lastVisit != null)%0A        %7B%0A            lastVisit.left = null;%0A            lastVisit.right = root;%0A        %7D%0A        %0A        lastVisit = root;%0A        %0A        flatten(root.left);%0A        flatten(savedRight);%0A           %0A%0A        %0A    %7D%0A%7D

Flatten Binary Tree to Linked List