string1 rotation of string2, algorithm complexity

To check if string1 is rotation of string2.

One way: str1 += str1; and then check if str2 is substring of str1. Time n^2, space n. (is this complexity correct?)

Second way: 2 for loops, and inner one uses '%' after increment. So time n^2, space 1. (is this complexity correct?)

Is there any other way to do it?

Thank you! :)
You're correct about the complexities.

I don't think there is an algorithm better than n2 and 1.
Last edited on
Topic archived. No new replies allowed.