There is no one right answer. It depends greatly on the personal preferences of individuals, and the specifics of any given question. People are free to vote based on what they feel is appropriate, so in a general sense the "best" option is entirely up to the voting practices of the community. That can change based on the tags your in, the time of day the question is posted, luck, the time of year, the quality of the question, the quality of the answer, the popularity of the question, and any number of other factors.
It's an issue that is reasonably controversial; there are many people on different sides, and a such there is no clear singular community consensus across the network. You'll simply need to determine on your own what you want to do, along with what "the community" of active members for that particular question is likely to think appropriate.
Of course, the fact that a question is related to a homework problem as virtually no direct effect on its quality. There are fantastic questions that happen to be related to a homework problem someone has, and there are terrible questions related to a homework problem someone has.
Likewise, there are factors to answer quality beyond just whether there is a complete code answer. An answer that describes the solution without code can be good or bad, based on what it describes, how well it describes it, etc. An answer with a full code solution can also vary in quality; it may be a really good solution to the problem, or it may not be. This adds yet another (major) variable to consider when evaluating such answers.