Valid Palindrome

来源:互联网 发布:idc销售系统源码 编辑:程序博客网 时间:2024/04/24 12:28

最简单的题了,先预处理一下会比较好做。

class Solution {public:    bool isPalindrome(string s) {        s = preProcess(s);        int l = 0, r = s.length() - 1;        while (l < r) {            if (s[l] == s[r]) {                l++;                r--;            }            else                return false;        }        return true;    }    string preProcess(string s) {        string res = "";        for (int i = 0; i < s.length(); i++) {            if (s[i] >= 'a' && s[i] <= 'z') {                res += s[i];                continue;            }            if (s[i] >= 'A' && s[i] <= 'Z') {                res += s[i] - 'A' + 'a';                continue;            }            if (s[i] >= '0' && s[i] <= '9')                res += s[i];        }        return res;    }};

http://oj.leetcode.com/problems/valid-palindrome/

0 0