public void flatten(TreeNode root) {
        if (root == null)
            return;

        if (root.left != null) {
            rightMost(root.left).right = root.right;
            root.right = root.left;
        }

        root.left = null;

        flatten(root.right);
    }