I would indeed suggest to post an own answer. Give attribution to the users you derived an answer from and make sure it is more than just a code dump of the working code. The answer should really stand on its own.
I would also suggest accepting the answer that helped you best if your work is a derivative from that answer, not your own. An exception can be made if your post is much better than the work you derived your answer from.
Never post working code as a comment or an edit of your question. That isn't the place for answers.