My University professor copied parts of my assignment for the sample solution. Should he have credited me?
Yes, this is both flattering and weird. I would call it unprofessional and tacky.
He should have thanked you for the nice answer and asked your permission to post parts of it.
Whether you should have public credit for that work may depend on policies at your school and on how you and the instructor think about the impact of such an announcement on other students.
Do stick with this:

Anyway I am not gonna say anything to him but I did laugh at the
thought that if I ever use my answer again in a similar topic imagine
if then I am accused of plagiarism from myself and/or him :)