Skip to content

Commit e16e96b

Browse files
Update valid_palindrome.py
1 parent dabaf69 commit e16e96b

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

valid_palindrome.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,36 @@ def isPalindrome(self, s: str) -> bool:
1313
return False
1414
i += 1
1515
j -= 1
16-
return True
16+
return True
17+
18+
'''
19+
CPP solution -
20+
21+
class Solution {
22+
public:
23+
bool isPalindrome(string s) {
24+
25+
if(s.length() == 0) return true;
26+
27+
int m=s.length()-1;
28+
int i=0;
29+
30+
while(i<m) {
31+
32+
if(isalnum(s[i]) && isalnum(s[m])) {
33+
if(tolower(s[i]) != tolower(s[m]))
34+
return false;
35+
else{
36+
i++, m--;
37+
continue;
38+
}
39+
}
40+
else {
41+
if(!isalnum(s[i])) i++;
42+
if(!isalnum(s[m])) m--;
43+
}
44+
}
45+
return true;
46+
}
47+
};
48+
'''

0 commit comments

Comments
 (0)