You can leave the hotel or apartment at any time, the main thing is to notify the property administrator, hand over the keys, and go through the check-out procedure, if necessary.
Unfortunately, not all such cases will result in a partial refund; the decision will depend on the hotel. More on this in a separate article.