@@ -0,0 +1,1122 @@
+package leetcode;%0A%0A/**%0A * https://oj.leetcode.com/problems/flatten-binary-tree-to-linked-list/%0A */%0Apublic class Problem114 %7B%0A    public static class TreeNode %7B%0A        int val;%0A        TreeNode left;%0A        TreeNode right;%0A%0A        TreeNode(int x) %7B%0A            val = x;%0A        %7D%0A    %7D%0A%0A    public void flatten(TreeNode root) %7B%0A        flatten(null, root);%0A    %7D%0A    %0A    private TreeNode flatten(TreeNode parent, TreeNode node) %7B%0A        if (node == null) %7B%0A            return node;%0A        %7D%0A        TreeNode left = node.left;%0A        TreeNode right = node.right;%0A        if (parent == null) %7B%0A            parent = node;%0A        %7D else %7B%0A            parent.left = null;%0A            parent.right = node;%0A        %7D%0A        if (node.left != null && node.right == null) %7B%0A            return flatten(node, left);%0A        %7D else if (node.left == null && node.right != null) %7B%0A            return flatten(node, right);%0A        %7D else if (node.left != null && node.right != null) %7B%0A            TreeNode l = flatten(node, left);%0A            return flatten(l, right);%0A        %7D else %7B%0A            return node; %0A        %7D%0A    %7D%0A%7D%0A

Solve problem 114