public class Palindrome
{
static private String text;
static private int firstIndex;
static private int lastIndex; public static boolean isPalindrome(String text, int firstIndex,int lastIndex)
{
text = text.toLowerCase();
firstIndex = 0;
lastIndex = text.length()-1;
for( int i=0; i < text.length(); i++)
{
char letter = text.charAt(i);
if(character.isLetterOrDigit(letter)
这里 我要忽略标点和空格部分,但是怎么继续写下去呢??}
if (firstIndex >= lastIndex) return true; // Base Case
else if (text.charAt(firstIndex) != text.charAt(lastIndex)) return false;
else {
return isPalindrome(text, firstIndex + 1, lastIndex -1);
} }}
{
static private String text;
static private int firstIndex;
static private int lastIndex; public static boolean isPalindrome(String text, int firstIndex,int lastIndex)
{
text = text.toLowerCase();
firstIndex = 0;
lastIndex = text.length()-1;
for( int i=0; i < text.length(); i++)
{
char letter = text.charAt(i);
if(character.isLetterOrDigit(letter)
这里 我要忽略标点和空格部分,但是怎么继续写下去呢??}
if (firstIndex >= lastIndex) return true; // Base Case
else if (text.charAt(firstIndex) != text.charAt(lastIndex)) return false;
else {
return isPalindrome(text, firstIndex + 1, lastIndex -1);
} }}
你可以把你字符串中的 标点和空格都换掉。换成“”
第二中方法你可拆分字符串。拆分点就是有标点和空格的地方。然后去掉然后在链接组成新的字符串。