Don’t use label in hash map. Rather use type RandomListNode for both keys and values.
My solution did not work when I tried to use labels?
Are there duplicates or?
Nothing is specified in problem statement regarding duplicates, so best practice would be to not use label as your key.
Indeed the correct advice. Thanks
Can someone explain why using RandomListNode as key worked but not label?
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.