标签:style blog color leetcode io div
class Solution { public: bool isPalindrome(string s) { int len = s.length(); //if (len < 1) return true; int p = -1, q = len; while (true) { char a, b; while (++p < len && !(a = check2lower(s[p])) ); while (--q > -1 && !(b = check2lower(s[q])) ); if (p >= q) return true; if (a != b) { return false; } } return true; } char check2lower(char ch) { if (ch <= ‘9‘ && ch >= ‘0‘) return ch; if (ch <= ‘z‘ && ch >= ‘a‘) return ch; if (ch <= ‘Z‘ && ch >= ‘A‘) return ch + ‘a‘ - ‘A‘; return ‘\0‘; } };
跟快排的结构有点类似
LeetCode Valid Palindrome,布布扣,bubuko.com
标签:style blog color leetcode io div
原文地址:http://www.cnblogs.com/lailailai/p/3813791.html