>and just out of intrest was wondering about it's time complexity
Um, O(N). Loops are what you look for primarily when working out time complexity, and since there's only one loop, it's pretty straightforward.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
It is O(length), but what is the variable s? Is it a string of fixed size? Is it a variable length string? If so, then generally, your running time is O(length * s.length()), because the indexOf method should take O(s.length()) time in the average and worst case. Holding s.length() fixed, your running time is O(length).
Rashakil Fol
Super Senior Demiposter
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
http://www.eternallyconfuzzled.com/articles/bigo.html
I usually don't plug my own stuff out of principle, but any other explanations I've found have been overly mathematical and confusing even to me. And I like to think that I have an above average understanding of these things. :rolleyes:
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401