public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param str string字符串 待判断的字符串 * @return bool布尔型 */ public boolean judge1(String str) { // write code here char[] array = str.toCharArray(); int max_index = array.length - 1; if (max_index == 0) return true; for (int i = 0; i <= max_index; ++i) { if (array[i] != array[max_index - i]) return false; if (i == max_index - i || (max_index - i -i) == 1) break; } return true; } public boolean judge2(String str) { return new StringBuilder(str).reverse().toString().equals(str); } public boolean judge(String str) { int max_index = str.length() - 1; if (max_index == 0) return true; char[] array = str.toCharArray(); int loop = max_index / 2; for (int i = 0; i < loop; ++i) { if (array[i] != array[max_index - i]) return false; if (i == max_index - i || (max_index - i -i) == 1) break; } return true; } public boolean judge3(String str) { int max_index = str.length() - 1; if (max_index == 0) return true; int loop = max_index / 2; for (int i = 0; i < loop; ++i) { if (str.charAt(i) != str.charAt(max_index - i)) return false; if (i == max_index - i || (max_index - i -i) == 1) break; } return true; } }