//查询字符串中第一次只出现一次的字符,要求时间复杂度为O(1)
#include<iostream>
using namespace std;
char find_first_unique_char(char *str)
{
int data[256];
memset(data, 0, sizeof(data));
char *p = str;
if (*p == '\0')
return '\0';
while (*p != '\0')
data[*p++]++;
while (*str != '\0')
{
if (data[*str] == 1)
return *str;
str++;
}
return '\0';
}
int main()
{
char *str = "abcdfeeeabcdk";
printf("%c\n", find_first_unique_char(str));
system("pause");
return 0;
}