I suggest a variation of Captain Emacs's suggestion, namely to write the solution (in your own words) and hand it in, including an explanation of where and how you found the reference that contained the solution, and including a note stating that because you hadn't arrived at the solution by yourself, you would be happy to accept an alternative assignment. However, I doubt that that would be necessary. The instructor likely cares to know mainly that you reached a good level of understanding of the material covered by the question, and would not care as much how you arrived at that understanding.
I should also note that it's not clear to me that not including a citation would represent academic dishonesty. It certainly would if you were specifically instructed not to use the internet as an aid to solving the homework, or if you copied the solution verbatim rather than read it, understand it and write it in your own words, but otherwise, whether this was seen or dishonest or not would depend on whether there was an (implicit or explicit) assumption that students are allowed to use any sources they wish to in order to arrive at a solution, as long as the solution they hand in is written by them, in their own words, and represents genuine understanding that they have attained. With that said, it's best to be as honest as possible, not least because you haven't done anything wrong by stumbling on the solution accidentally, so I would greatly favor the honest approach advocated above or the similar one suggested by Captain Emacs.