If you misunderstood the question and ended up posting an answer that contains useful content, but is not in fact an answer to the question, then you should delete it. We want to have answers that answer the question.
If you consider the content useful and feel that it should be preserved, then you can ask a new question that asks the question that your answer answers, and then post your answer to that question.
As always when self answering questions, keep in mind that the question an answer will be evaluated for quality independently, and each needs to be up to the same quality standards as every other post on the site. For a case like this, you shouldn't be just posting a throw-away question that's just a placeholder for your answer, but rather asking a quality question that you would want to see someone else ask (if they didn't know the answer).