In this case, since you have enough reputation, you should simply upvote the answer that worked for you. If you didn't have enough reputation to upvote, you should still click the upvote button, as anonymous feedback is counted and can be accessed through Stack Exchange Data Explorer (and I use it for some moderation activities), though it does not affect the visible post score.
Post score is intended to indicate how useful the answer is. Arguably the strongest form of usefulness is that it worked for someone else :) so to indicate that the answer worked for you, upvoting is the intended method of communication!
When you do have sufficient reputation to comment, I would still advise you in general not to write a comment saying something worked for you. It's unlikely that a comment saying "this worked for my slightly different case" would have any value, unless, possibly, you specified what was different about your case, like "I was trying the same thing on 16.04 and this answer worked for me", or "I was using [some specific hardware] and this worked for me" (on a hardware-specific question). Such a comment might arguably be slightly useful. If it were a case where such a comment had value, then the author of the post might see the comment and update their post to say something like "according to [you] this also works for [different scenario]" and then the comment could be deleted. Keeping the site up to date over time is a challenge we haven't quite worked out. That's definitely not the intended purpose of comments, but I guess it's one of their possible uses.
Still, I certainly wouldn't consider it necessary to make such a comment, and if I saw a comment like that that seemed to have little value, I would flag it as obsolete. Comments are easily deleted, and once deleted, nobody except mods can see them. So, we do not expect much value from comments. Voting, on the other hand, is vital to the site, and I encourage you to do it prolifically. If useful posts are not upvoted, nobody will know that they are useful, and if bad posts aren't downvoted, people will not realise that following them may be a bad idea.
Oh and yes, you're right, you definitely should not add an answer saying "this answer worked for me". Such an answer would be considered Not an answer and would be deleted (unless nobody noticed it and flagged it). If someone repeatedly makes posts that are deleted by reviewers and/or mods, eventually the site will automatically block them from answering questions until they manage to do enough things the system values (like writing posts that are upvoted) to get the ban lifted.