2 ms·
No expert on algorithms, but: Sorting an array is O(n*log(n)) Hashmap operations are constant time, and walking through array to put stuff in it is O(n) So,
by 988747 4y ago
No expert on algorithms, but:
Sorting an array is O(n*log(n))
Hashmap operations are constant time, and walking through array to put stuff in it is O(n)
So, implementation based on Hashmap should be slightly faster. It requires extra memory, though.
- IshKebab 4y agoOh yeah that is true. I am an idiot.