Hacker News new | past | comments | ask | show | jobs | submit login

but isn't find() an O(n) operation already?



Indeed! Which is why find() is not a member function on vector (so my snippet above is wrong - I just missed that part). It's a global function, so you need to do:

   if (find(x, v.begin(), v.end()) != v.end()) ...
For maps and sets, find is a member function though. Same principle - if it is implemented in some optimized way, the class provides it directly, but not otherwise.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: