package com.fishercoder.solutions;

import com.fishercoder.common.classes.TreeNode;

public class _114 {

    public static class Solution1 {
        public void flatten(TreeNode root) {
            while (root != null) {
                if (root.left != null) {
                    TreeNode previousNode = root.left;
                    while (previousNode.right != null) {
                        previousNode = previousNode.right;
                    }
                    previousNode.right = root.right;
                    root.right = root.left;
                    root.left = null;
                }
                root = root.right;
            }
        }
    }
}

@@ -666,11 +666,817 @@
  %7D%0A    %7D
+%0A%0A    public static class Solution2 %7B%0A%0A        /**%0A         * Credit: https://leetcode.com/problems/flatten-binary-tree-to-linked-list/solution/%0A         */%0A        public void flatten(TreeNode root) %7B%0A            flat(root);%0A        %7D%0A%0A        private TreeNode flat(TreeNode curr) %7B%0A            if (curr == null) %7B%0A                return null;%0A            %7D%0A            if (curr.left == null && curr.right == null) %7B%0A                return curr;%0A            %7D%0A            TreeNode leftTail = flat(curr.left);%0A            TreeNode rightTail = flat(curr.right);%0A            if (leftTail != null) %7B%0A                leftTail.right = curr.right;%0A                curr.right = curr.left;%0A                curr.left = null;%0A            %7D%0A            return rightTail == null ? leftTail : rightTail;%0A        %7D%0A    %7D
 %0A%7D%0A

add a solution for 114