Hash Map

  • reduce time complexity, o(n^2) -> o(n)
  • C++ unordered_map, look up o(1), insert o(1)
  • unordered list
  • Use mp.find() instead of mp.count as mp.find() would return an iterator, can use
auto it = mp.find(complement);  
if (it != mp.end()) { 
 return {it->second, i};
 }

Which is faster than

if (mp.count(complement)){
  return{mp[complement],i}
  }

Leave a Reply

Discover more from Daily Learning

Subscribe now to keep reading and get access to the full archive.

Continue reading