It is pretty much impossible to detect software plagiarism, especially on leetcode style questions as only 1 style or pattern is the most efficient answer.
Though if a student changes it sufficiently enough, they might begin to actually see the invariants and ideas and actually learn the material.