4 ms·
The problem is your solution (as shown) will grow in memory forever. You can add code to get around that (e.g. expiration times), but it also might be easier (
by sbov 14y ago
The problem is your solution (as shown) will grow in memory forever.
You can add code to get around that (e.g. expiration times), but it also might be easier (and have less memory usage) to write your own dict class that overwrites values when a collision occurs.
Also, since the OP seems to be using java: if you can get away with storing a primitive data type in an array (e.g. array of int or long) you can save a lot of memory vs using a Set or Map.