It depends on the terms of your lease. Typically there's an escape clause: there may be a fee, you may be expected to surrender the deposit, et cetera. You may also be able to sublet your apartment, where your name remains on the lease, but someone else is actually paying the rent.
You may also be able to ask your landlord politely.