private void helper(TreeNode root) {
        if (root == null)
            return;
        if (prev == null)
            prev = root;
        else {
            prev.right = root;
            prev = root;
        }

        TreeNode left = root.left;
        TreeNode right = root.right;
        root.left = null;
        helper(left);
        helper(right);
    }