package Others;class Palindrome {private String reverseString(String x) { // *helper methodStringBuilder output = new StringBuilder(x);return output.reverse().toString();}public boolean FirstWay(String x) { // *palindrome method, returns true if palindromeif (x == null || x.length() <= 1)return true;return x.equalsIgnoreCase(reverseString(x));}public boolean SecondWay(String x) {if (x.length() == 0 || x.length() == 1)return true;if (x.charAt(0) != x.charAt(x.length() - 1))return false;return SecondWay(x.substring(1, x.length() - 1));}/*** This method ignores all non-alphanumeric characters and case runs in O(n)* where n is the length of s** @param s String to check* @return true if s is palindrome else false*/public boolean isPalindrome(String s) {s = s.toLowerCase().trim();StringBuilder sb = new StringBuilder();for (char c : s.toCharArray()) {if (Character.isLetter(c) || Character.isDigit(c))sb.append(c);}s = sb.toString();int start = 0;int end = s.length() - 1;while (start <= end) {if (s.charAt(start++) != s.charAt(end--))return false;}return true;}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。