2022年11月26日 星期六

[409] Longest Palindrome

感覺好像是有點空虛的題目XD
就純粹算數的感覺?!並且最後有一點點偷吃步 (扮鬼臉)
int longestPalindrome(char * s){
int *hash= calloc(58, sizeof (int));
int len = strlen(s);
int count=0;
for (int i=0;i<len;i++)
{
if (hash[s[i]-'A']==0)
hash[s[i]-'A']=1;
else
{
hash[s[i]-'A']=0;
count+=2;
}
}
if (len> count)
count++;
return count;
}

沒有留言:

張貼留言