Skip to content

Commit 29dc019

Browse files
committed
solved Valid Palindrome
1 parent f644e1f commit 29dc019

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

valid-palindrome/wclee2265.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// https://leetcode.com/problems/valid-palindrome/
2+
3+
class Solution {
4+
public:
5+
bool isPalindrome(string s) {
6+
string ns;
7+
for(char c : s){
8+
if(c >= '0' && c <= '9') ns += c;
9+
else if(c >= 'A' && c <= 'Z') ns += (c + 32);
10+
else if(c >= 'a' && c <= 'z') ns += c;
11+
}
12+
13+
int n = ns.size();
14+
for(int i=0; i<n/2; i++) {
15+
if(ns[i] != ns[n-i-1]) return false;
16+
}
17+
return true;
18+
}
19+
};

0 commit comments

Comments
 (0)