剑指Offer:第一个只出现一次的字符

时间:2023-03-08 15:41:48

题目:在字符串中找出第一个只出现一次的字符。如输入"abaccdeff",这输出'b'

// 第一个只出现一次的字符

#include <stdio.h>

char first_not_repeat_char(char *s)
{
int count[]={};
char *pkey; if( s==NULL )
{
printf("The string should not be NULL\n");
return '\0';
} for(pkey=s; *pkey != '\0'; pkey++)
count[*pkey]++;
for(pkey=s; *pkey != '\0'; pkey++)
if( count[*pkey] == )
return *pkey; return '\0';
} int main(void)
{
char s[];
printf("Please input a string: ");
scanf("%s",s);
char first = first_not_repeat_char(s);
if(first != '\0')
printf("First not repeat char is: %c\n",first);
else
printf("Not found\n");
char *p=; return ;
}