say I use the following methods to search for a palindrome. I know the first one is O(n) because it goes through entire string. Does the .reverse() in the StringBuffer also do O(n)? Im not worried about finding a better way to problem Im trying to understand if the reverse method physically reverses the string or is it much more efficient than that?? Thanks
public static boolean isAPalindrome(String s1){
String tmp = "";
int length = s1.length();
for(int i = 0; i < s1.length(); i++){
tmp += s1.charAt(s1.length()-i-1);
}
if (s1.equals(tmp)) return true;
return false;
}
public static boolean isAPalindrome(String s1){
StringBuffer a = new StringBuffer(s1);
return s1.equals(a.reverse().toString());
}