inlinecharLower(char c){ return (c <= 'z' && c >= 'a') ? c : c + 'a' - 'A'; } inlineboolcheck(string &s, int i){ return (s[i] <= '9' && s[i] >= '0') || (s[i] <= 'z' && s[i] >= 'a') || (s[i] <= 'Z' && s[i] >= 'A'); } inlineintnextLeft(string &s, int i, int end){ while(i < end && !check(s, i)) { i++; } return i; } inlineintnextRight(string &s, int i, int end){ while(i > end && !check(s, i)) { i--; } return i; } boolisPalindrome(string s){ int n = s.size(); int last = nextRight(s, n-1, 0); int first = nextLeft(s, 0, last);
while(first < last && Lower(s[first]) == Lower(s[last])) { last = nextRight(s, last - 1, first); if (first < last) first = nextLeft(s, first + 1, last); } return first == last; }