Skip to content

Commit 26ce291

Browse files
committed
valid-palindrom solution
1 parent 1ae2729 commit 26ce291

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

valid-palindrome/dylan-jung.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public:
3+
bool isPalindrome(string s) {
4+
string p;
5+
for(char const& c: s) {
6+
if('A' <= c && c <= 'Z') {
7+
p.push_back(c - 'A' + 'a');
8+
}
9+
else if('a' <= c && c <= 'z') {
10+
p.push_back(c);
11+
}
12+
else if ('0' <= c && c <= '9') {
13+
p.push_back(c);
14+
}
15+
}
16+
int start = 0, end = p.size()-1;
17+
while(start <= end) {
18+
if(p[start++] != p[end--]) return false;
19+
}
20+
return true;
21+
}
22+
};

0 commit comments

Comments
 (0)