I have the function below that finds the longest non repeating sub-string in a string.
I know the for loop is O(n) but what will be the additional time by searching current char in tmp string in call to function indexOf.
public static String find(String input) {
String currentLongest = input.length() > 0 ? "" + input.charAt(0) : "";
String tmp = currentLongest;
for (int i = 1; i < input.length(); i++) {
int index = tmp.indexOf(""+input.charAt(i));
if (index == -1) {
tmp = tmp + input.charAt(i);
if (tmp.length() > currentLongest.length())
currentLongest = tmp;
} else
tmp = tmp.substring(index+1)+input.charAt(i);
}
return currentLongest;
}