leetcode-125-Valid Palindrome

問題

題目:[leetcode-125]

思路

先預處理下,然後利用庫即可。

代碼

class Solution {
public:
    bool isPalindrome(string s) {
        std::string tmp;
        int sz = s.size();
        for(int i = 0; i < sz; ++i){
            if( isalpha(s[i]) ) tmp.push_back( tolower(s[i]) );
            else if( isdigit(s[i]) ) tmp.push_back( s[i] );
        }
        return equal( tmp.begin(), tmp.end(), tmp.rbegin() );
    }
};
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章