您的位置:首页 > 其它

leetcode---Valid Palindrome

2016-04-09 21:58 330 查看
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

For example,

“A man, a plan, a canal: Panama” is a palindrome.

“race a car” is not a palindrome.

class Solution {
public:
bool isPalindrome(string s)
{
char ss[100000];
int len = s.length();
int index = 0;
for(int i=0; i<len; i++)
{
if(isalpha(s[i]))
ss[index++] = toupper(s[i]);
if(isdigit(s[i]))
ss[index++] = s[i];
}
int l = 0;
int r = index - 1;
while(l < r)
{
if(ss[l] != ss[r])
return false;
l++;
r--;
}
return true;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: