publicclassPalindrome{staticprivateStringtext;staticprivateintfirstIndex;staticprivateintlastIndex;publicstaticbooleanisPalindrome(Stringtext,intfirstIndex,intlastIndex){...
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);
}
}
}
展开