If I copy a clean solution from stackoverflow, I put it into a separate file with the appropriate license header. IMO that's the absolute minimum degree of separation that any imported code, whether from StackOverflow or AI, should have.
Even if I then edit it to adapt and modify it, I'll just add my copyright header, but I can't replace/remove the original one.