A community can have many owners, and must always at least one owner. Thus, if you're the only community owner you will not be able to leave the community. Below steps explains how you can transfer ownership to another person.
Only community owners can transfer ownership of a community.
1
If the person is not already a member, then invite the person you want to transfer ownership to. Already when you invite the person you can choose the owner role for the person.
2
If the person is already a member, then the change member role to owner.
3
Last step is to either leave community or ask the new owner to change your role to reader, curator or manager in case you wish to still be a member of the community.