A document that helped me a lot is How to ask questions the smart way by ESR.
How do I answer questions the smart way?
I follow these steps to answer a question:
Obviously, the answer has to be correct. If you're getting unsure, do some research at Google.
When you discover that the answer is bad (misread question, wrong answer), delete the answer (even if it has some upvotes already). If you have a great solution, edit the answer while it's deleted, and finally undelete it.