Just an advice: Don't use label in hash map


#1

Don’t use label in hash map. Rather use type RandomListNode for both keys and values.


#2

Why?
My solution did not work when I tried to use labels?
Are there duplicates or?


#3

Nothing is specified in problem statement regarding duplicates, so best practice would be to not use label as your key.


#4

Indeed the correct advice. Thanks


#5

Can someone explain why using RandomListNode as key worked but not label?


#6

Because label can be duplicated, so when you’ll be assigning a RandomListNode to some label that is duplicated, it will override the previous value in that label, since keys can’t be duplicated in a map, they are simply overwritten by the newer value.