I have run into this several times: I answer a question and someone else provides the same answer with roughly the same amount of quality within a few seconds. What's the appropriate thing to do at that point? Should one of you delete your answer? How should the questioner decide?
If you think you can improve your answer, do so. Then they won't be identical anymore, and the questioner will have an easier time deciding which one to accept.
Otherwise, consider deleting your answer. You don't have to - you can wait it out and hope for luck... But while you're waiting, the other author may well improve his answer, thus reducing your chances. And even if he doesn't, leaving two identical answers is just leaving noise.
If you feel you can improve your answer and you can be bothered to spend even more time on a question that's already been answered, go for it. Otherwise what you should do is take Stack Overflow less seriously and just leave it. You might pick up some rep depending on which of the simultaneous posts comes out on top until people vote. I wouldn't delete my answer though unless the other person's is obviously much better.