You can leave the hotel or apartment at any time, you will need to notify the property administrator, hand over the keys, and go through the check-put procedure, if necessary.
In some cases, there is an option to refund a portion of the payment if you check out early. More on this in a separate article.