125. Valid Palindrome
All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : June 07, 2024
Last updated : July 01, 2024
Related Topics : Two Pointers, String
Acceptance Rate : 49.09 %
bool isPalindrome(char* s) {
int left = 0;
int right = 0;
while (s[right + 1]) {
right++;
}
while (left < right) {
if (s[left] <= 90 && s[left] >= 65) {
s[left] += 32;
} else if (!((s[left] <= 57 && s[left] >= 48) || s[left] <= 122 && s[left] >= 97)) {
left++;
continue;
}
if (s[right] <= 90 && s[right] >= 65) {
s[right] += 32;
} else if (!((s[right] <= 57 && s[right] >= 48) || (s[right] <= 122 && s[right] >= 97))) {
right--;
continue;
}
if (s[left] != s[right]) {
return false;
}
left++;
right--;
}
return true;
}
class Solution:
def isPalindrome(self, s: str) -> bool:
singleStr = re.sub('[^A-Za-z0-9]', '', s).lower()
for i in range(len(singleStr) // 2) :
if not singleStr[i] == singleStr[len(singleStr) - i - 1] :
return False
return True