int FirstNotRepeatingChar(char* str ) {
// write code here
if(*str == '\0')
{
return -1;
}
//创建两个指针,p1往前跑看是否与p2位置的值相等
char* p1 = str + 1;
char* p2 = str;
while(*p2 != '\0')
{
while(*p1 != *p2 && *p1 != '\0')
{
p1++;
}
if(*p1 == '\0')
{
return p2-str;
}
while(*p2 != '\0')
{
p2++;
//判断p2位置之前有没有出现与之相等的位置
char* p = str;
while(*p != *p2 && p != p2)
{
p++;
}
if(p == p2)
{
p1 = p2 + 1;
break;
}
}
}
return -1;
}

京公网安备 11010502036488号