As long as it’s within the alotted editing time you can. I’ve sometimes done that if an identical (or even more correct answer) was posted during the time I was typing mine.
You can’t erase the fact that you made a post but I’ve just erased all the content and left a period or an ellipse.
After the editing window has passed, your out of luck unless you can appeal to the mercy of a mod. If your reason is good enough they can send it back to you for editing and you can change it.