Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
And here I am implementing PriorityQueue with HashMap XD
Character.compare('1','2'); //out: -1
This output means that that "2:..." will go before "1:..." as required in the solution;
I think in question it is specifically mentioned that hashcode & equals contract has been already taken care of So no need to worry about that key collision. But still yes to be on more safer side we can use this Identity hashmap.
so clever done,i was stuck by this kata
For each node, lookup in a map is performed twice:
map.containsKey(current)
andmap.put(current, i)
. This can be avoided:put
returns previous value associated with key, which can be used instead to check existance of the node instead ofcontainsKey
.Love it
Bold of you to assume I don't know how the equals and hashCode methods are implemented.
Thank you for sharing the tip with the IdentityHashMap. I did not know about IdentityHashMap. That's why I used a LinkedList and the '==' operator. I didn't realized that I also could put the object identity to a map :-D
You don't know something about the Node class. You don't know how the equals and the hash method is implemented. So to use the HashMap is not a great idea.
Please, try to avoid loop inside loop if possible and in this task it is possible^)
Simple and deep. Very tricky code!
I did not know about IdentityHashMap, thanks for sharing! That would definitely work here.
When I used a HashMap, I used Node.toString() as the key. Now I understand that I was making an assumption that the toString() and hashCode() methods where no overridden in a way that would break my HashMap.
Nice solution. Mine is simmilar but much longer. It feels good to see the top solution is close to mine :)
This comment is hidden because it contains spoiler information about the solution
Frankly, I don't like this solution.
It is not readable, and logic is quite complex for no apparent reason.
Compare with my solution to see what I mean
Loading more items...