时间限制:1秒 空间限制:32768K 热度指数:279851
本题知识点: 字符串
算法知识视频讲解
题目描述
在一个字符串(0<=字符串长度<=10000,全部由字母组成)中找到第一个只出现一次的字符,并返回它的位置, 如果没有则返回 -1(需要区分大小写).
int FirstNotRepeatingChar(string str) {
int len=str.length();
cout<<len<<endl;
for(int i=0;i<len;i++)
{
int count=0;
for(int j=0;j<len;j++)
{
if(str[i]==str[j])
count++;
if(count==2)
break;
}
if(count==1)
{
cout<<str[i]<<endl;
return i;
}
cout<<count<<endl;
}
return -1;
}