Hacker News new | ask | show | jobs
by HoppedUpMenace 2326 days ago
Here's a pretty embarrassing one ;):

int index = 0; while (!element.equals(sortedList.get(index)) && sortedList.size() > ++index); return index < sortedList.size() ? index : -1;

3 comments

Asking for the sortedList size with every iteration of that loop. haha, ouch! :)
that's the slowest subroutine I've ever seen
Thanks for sharing!