Having run the code on leetcode, I know this code is correct. Could you explain why I’m getting an error?
Node current1 = l1;
Node current2 = l2;
HashSet set = new HashSet();
while(current1 != null){
set.add(current1);
current1 = current1.next;
}
while(current2 != null){
if(set.contains(current2)) return current2;
current2 = current2.next;
}
return null;