Yes, flagging the comment is appropriate but I'd go with a custom comment in this case, instead of the standard option "No longer needed". The reason is that the ♦ moderator handling the flag will see the post and the flagged comment in the queue, but not your own comment. Some (on busy sites like Stack Overflow, almost all) flags are handled from the queue, and you risk your flag being declined because of this; all the moderator will see is a subpar-quality post and a justified comment.
A custom message "no longer needed, I've posted an improved version of this comment" isn't that much work to type and 100% clear to the moderator. They'll visit the post, notice that you're right and delete the flagged comment.