Help me in solving PREP55 problem

My issue

run time error

My code

  
class Solution
{
    
    Node removeDuplicates(Node head) 
    {
         // Your code here
        HashSet<Integer> hs = new HashSet<>(); 
        Node curr=head;
        Node prev=null;
         
        while(curr!=null){
            int val = curr.data;
            if (hs.contains(val))
                prev.next=curr.next;
                    
            else{
                hs.add(val);
                prev=curr;
            }
                 
            curr=curr.next;
        }
       
        return head;
    }
}

Learning course: Linked Lists
Problem Link: Practice Problem in - CodeChef