I had this happen to me the other day - literally, yesterday. I was working on an answer to a new question, and boing! someone posted something quite similar to it. I almost decided not to post the answer, feeling that the effort would have been duplicated.
I decided to rewrite the answer. I started over in terms of writing, but I kept some of the same basic ideas. I went back and added more details, sources, and explanations. I ended up posting it about half an hour after the other user, but as of this writing, mine has more upvotes.
Why? It's likely pure chance; the difference is only 2-1. But I think that the reason mine got more votes - as has been the case sometimes in the past - is that I added a lot more detail, and gave an explanation that was a little more in-depth, though longer. Worldbuilding is great insofar as people don't just look at a question for a quick fix. They look because they're intrigued by the title, and then the question body, and hopefully the answers. This means that they'll likely stop and read a well-written answer, instead of skipping it because I was ninja'd by the fastest gun in the west.
The moral of the story? It's okay if your answer is similar to another person's. I encourage you to rewrite it. Nobody's going to downvote you because you wrote a similar answer, unless you wrote it the same way someone else did. However, I think people will upvote you if you take the time to make your answer better than the other(s).