v2 time O(n) space O(1) Accepted

forgot to add the last node when it's not a duplicate. this is a very common bug. need to be very cautious!!!