Remove method and added hash code

Changed the method to detect for duplicate to using a Set. This will
remove the duplicate without having to use a two for loops. Also, now
it doesn’t need a flag to keep track which one is the duplicate.