Skip to content

Commit 244fe7c

Browse files
committed
valid palindrome solution
1 parent cc44155 commit 244fe7c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

valid-palindrome/PDKhan.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public:
3+
bool isPalindrome(string s) {
4+
int left = 0;
5+
int right = s.length()-1;
6+
7+
while(left < right){
8+
while(left < right && !isalnum(s[left])) left++;
9+
while(left < right && !isalnum(s[right])) right--;
10+
11+
if(tolower(s[left]) != tolower(s[right]))
12+
return false;
13+
14+
left++;
15+
right--;
16+
}
17+
18+
return true;
19+
}
20+
};

0 commit comments

Comments
 (0)