Question: Hello, I'm trying to determine the algorithmic complexity of the function below, which determines if a string has been rotated (for example, a string abcd
Hello, I'm trying to determine the algorithmic complexity of the function below, which determines if a string has been rotated (for example, a string "abcd" has been rotated to "bcda"). I believe the following runs in O(n), but I just wanted to verify.
public class Rotate{
public static void main(String[] args) { String first = "abcd"; String second = "cdba";
System.out.println(isRotated(first, second); } private static boolean isRotated(String first, String second){ if(first == null or second == null) {
return false;
} if (first.length == second.length && (first + second).indexOf(str2) > 0) {
return true;
}
return false; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
