package com.fishercoder.solutions;

import com.fishercoder.common.classes.TreeNode;

/**
 * 114. Flatten Binary Tree to Linked List
 *
 * Given a binary tree, flatten it to a linked list in-place.

 For example,
 Given

   1
  / \
 2  5
/ \  \
3 4  6

 The flattened tree should look like:
  1
   \
   2
    \
    3
     \
     4
      \
      5
       \
       6

 Hints:
 If you notice carefully in the flattened tree, each node's right child points to the next node of a pre-order traversal.
 */
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;
            }
        }
    }
}

@@ -82,422 +82,8 @@
 e;%0A%0A
-/**%0A * 114. Flatten Binary Tree to Linked List%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%0A3 4  6%0A%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 Hints:%0A If you notice carefully in the flattened tree, each node's right child points to the next node of a pre-order traversal.%0A */%0A
 publ

refactor 114