forked from onlybooks/python-algorithm-interview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1-4.c
More file actions
25 lines (23 loc) · 664 Bytes
/
1-4.c
File metadata and controls
25 lines (23 loc) · 664 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// C
bool isPalindrome(char *s) {
int bias_left = 0;
int bias_right = 1;
int str_len = strlen(s);
for (int i = 0; i < str_len; i++) {
// 스킵 포인터 처리
while (!isalnum(s[i + bias_left])) {
bias_left++;
if (i + bias_left == str_len)
return true;
}
while (!isalnum(s[str_len - i - bias_right])) {
bias_right++;
}
if (i + bias_left >= str_len - i - bias_right)
break;
// 팰린드롬 비교
if (tolower(s[i + bias_left]) != tolower(s[str_len - i - bias_right]))
return false;
}
return true;
}