Skip to content

Commit b89cfe2

Browse files
committed
Updated C++ Solution
1 parent f4d7148 commit b89cfe2

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

C++/soln-string-problems/valid-palindrome.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,22 @@
1010
class Solution {
1111
public:
1212
bool isPalindrome(string s) {
13-
transform(s.begin(),s.end(),s.begin(), ::tolower);
14-
s.erase(remove(s.begin(),s.end(),' '),s.end());
1513
int len=s.size();
1614
int left=0;
1715
int right=len-1;
1816

1917
while(left<right){
20-
if(s[left]==s[right])
18+
if(!isalnum(s[left]))
19+
left++;
20+
else if(!isalnum(s[right]))
21+
right--;
22+
else if(tolower(s[left])!=tolower(s[right]))
23+
return false;
24+
else
2125
{
2226
left++;
2327
right--;
24-
}
25-
else{
26-
if((s[left]<'a' || s[left]>'z') && (s[left]<'0' || s[left]>'9'))
27-
left++;
28-
else if((s[right]<'a' || s[right]>'z') && (s[right]<'0' || s[right]>'9'))
29-
right--;
30-
else
31-
return false;
32-
}
33-
28+
}
3429
}
3530
return true;
3631
}

0 commit comments

Comments
 (0)