Skip to content

Commit b1fbb87

Browse files
committed
Time: 401 ms (5.09%), Space: 7.6 MB (50.12%) - LeetHub
1 parent 5128b4b commit b1fbb87

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public:
3+
bool isPalindrome(string str) {
4+
transform(str.begin(), str.end(), str.begin(), ::tolower);
5+
for(int i = 0; i < (int)str.length();)
6+
{
7+
if(!(str[i] >= 'a' && str[i] <= 'z') && !(str[i] >= '0' && str[i] <= '9'))
8+
str.erase(str.begin() + i);
9+
else i++;
10+
}
11+
12+
for (int i = 0; i < (int)str.length() / 2; i++)
13+
{
14+
if(str[i] != str[str.length() - 1 - i])
15+
return false;
16+
}
17+
return true;
18+
19+
}
20+
};

0 commit comments

Comments
 (0)