题目:
给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写。 说明:本题中,我们将空字符串定义为有效的回文串。
示例 1:
输入: “A man, a plan, a canal: Panama” 输出: true
示例 2:
输入: “race a car” 输出: false
简单介绍:
题目:验证回文串。题目难度:简单。
使用语言:java。
在这里插入代码片
在这里插入代码片
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package leerCode;
/**
*
* @author boom
*/
bool isPalindrome(string s) {
if(s.length () ==0)
return true;
int start = 0;
int end = s.length - 1;
while(start<end)
{
while (!IsCharOrNumber(s[start])) {
start++;
}
while (!IsCharOrNumber(s[end])) {
end--;
}
if (s[start] != s[end]) {
return false;
}
start++;
end--;
}
boolean IsCharOrNumber(char s) {
if ((s >= 'a' && s <= 'z') || (s >= '0' && s <= '9')) {
return true;
}
return false;
}
}