Skip to content

Commit 4d0a9e9

Browse files
Create valid palindrome
1 parent 10a0de1 commit 4d0a9e9

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

valid palindrome

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <ctype.h>
2+
#include <stdbool.h>
3+
#include <string.h>
4+
5+
bool isPalindrome(char * s) {
6+
int left = 0, right = strlen(s) - 1;
7+
while (left < right) {
8+
while (left < right && !isalnum(s[left])) left++;
9+
while (left < right && !isalnum(s[right])) right--;
10+
if (tolower(s[left]) != tolower(s[right])) return false;
11+
left++;
12+
right--;
13+
}
14+
return true;
15+
}

0 commit comments

Comments
 (0)