public static LinkedListNode unionLL(LinkedListNode head1, 
            LinkedListNode head2)
    {
        if (head1 == null || head2 == null) 
        {
            return null;
        }
        
        LinkedListNode result = null;
        LinkedListNode temp = head1;
        LinkedListNode temp2 = head2;
        HashSet<Integer> hs = new HashSet();
        
        while (temp != null && temp2 != null)
        {
            LinkedListNode nn = temp.getNext();
            LinkedListNode nn2 = temp2.getNext();
                        
            if (hs.add((int)temp.getData()))
            {
                LinkedListNode n = temp;
                temp.setNext(result);
                result = n;
            }
            
            if (hs.add((int)temp2.getData()))
            {
                LinkedListNode n = temp2;
                temp2.setNext(result);
                result = n;
            }
            
            temp = nn;
            temp2 = nn2;
        }
        
        return result;
    }