runnig

isPalindrome

Jan 31st, 2013
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. // http://leetcode.com/onlinejudge#question_125
  2.  
  3. class Solution {
  4. public:
  5.     bool isPalindrome(string s) {
  6.         // Start typing your C/C++ solution below
  7.         // DO NOT write int main() function
  8.         if(s.empty()) {return true;}
  9.        
  10.         const size_t N = s.size();
  11.         size_t i = 0, j = N - 1;
  12.         for(;i<j;)
  13.         {
  14.             const char a = s[i];
  15.             if(!isalnum(a)) { ++i; continue; }
  16.            
  17.             const char b = s[j];
  18.             if(!isalnum(b)) { --j; continue; }
  19.            
  20.             if(tolower(a) != tolower(b)) { return false;}            
  21.             ++i; --j;
  22.         }
  23.         return true;
  24.     }
  25. };
Advertisement
Add Comment
Please, Sign In to add comment