palindrome - 回文
alphanumeric - 字母数字
Have you consider that the string might be empty? This is a good question to ask during an interview.
Attention to :
1. only alphanumeric chars
2. ignore cases
3. empty string condition
Easy!
bool isalphanumeric(char c) { if(c>='A'&&c<='z' || c>='0'&&c<='9') return true; else return false; } class Solution { public: bool isPalindrome(string s) { // Start typing your C/C++ solution below // DO NOT write int main() function int len = s.size(); if(len == 0) return true; int lp = 0; int rp = len-1; while(lp < rp) { while(lp<rp && !isalphanumeric(s[lp])) lp++; while(lp<rp && !isalphanumeric(s[rp])) rp--; if(tolower(s[lp]) != tolower(s[rp])) return false; else { lp++;rp--; } } return true; } };