Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // http://leetcode.com/onlinejudge#question_125
- class Solution {
- public:
- bool isPalindrome(string s) {
- // Start typing your C/C++ solution below
- // DO NOT write int main() function
- if(s.empty()) {return true;}
- const size_t N = s.size();
- size_t i = 0, j = N - 1;
- for(;i<j;)
- {
- const char a = s[i];
- if(!isalnum(a)) { ++i; continue; }
- const char b = s[j];
- if(!isalnum(b)) { --j; continue; }
- if(tolower(a) != tolower(b)) { return false;}
- ++i; --j;
- }
- return true;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment