I answered the question. This answer was accepted. But OP wrote a comment that the proposed solution does not work well in one small case. I can fix it.
Which solution is better? Edit old answer or add new one?
In this case edit the answer. It sounds like your solution worked in the general case, but only failed on one edge case.
So the answer is still valid, but incomplete.
I totally agree with Chris: Edit the answer. What SO is about is to have great answers that can easily be found. Best case: the selected answer gives you all the information to solve the problem.
It is even encouraged to merge answers into one great answer (and giving credit to the other answerers contributing, at least by voting them up).
Having two answers with only a slight difference where one is slightly off only confuses. This is a site for great answers, not reputation.