Topic describes
Given a string, verify that it is a palindrome string, considering only alphanumeric characters, regardless of letter case.
Note: In this case, we define an empty string as a valid palindrome string.
Example 1:
Input: “A man, A plan, A canal: Panama”
Input: “race a car” Output: false
Copyright belongs to LeetCode. Commercial reprint please contact official authorization, non-commercial reprint please indicate the source.
Thought analysis
Process string, eliminate redundant characters, all lowercase conversion, and finally determine whether a palindrome string by comparing before and after
AC code
char isPalindrome(char * s){
int len = strlen(s);
char str[len];
int size = 0;
for (int i = 0; i < len; ++i) {
if (s[i] >= '0' && s[i] <= '9') {
str[size++] = s[i];
continue;
}
if (s[i] >= 'a' && s[i] <= 'z') {
str[size++] = s[i];
continue;
}
if (s[i] >= 'A' && s[i] <= 'Z') {
str[size++] = s[i] - 'A' + 'a';
continue; }}for (int i = 0; i < size / 2; ++i) {
if (str[i] == str[size - i - 1]) {
continue;
}
return 0;
}
return 1;
}
Copy the code
conclusion
Simple string problem
This article is participating in the “Nuggets 2021 Spring Recruitment Campaign”, click to see the details of the campaign