class Solution {
public:
bool isPalindrome(string s) {
if (s == "")
return true;
std::deque<char> dq;
for (const char & c : s){
if (!std::isalpha(c) && !std::isdigit(c))
continue;
else {
if (std::isalpha(c))
dq.push_back(std::tolower(c));
else
dq.push_back(c);
}
}
while(!dq.empty()){
if (dq.front() != dq.back())
return false;
else{
if (dq.size() == 1)
return true;
else{
dq.pop_front();
dq.pop_back();
}
}
}
return true;
}
};
180917 Solution one: using deque
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.