看有没有重复的字母出现,没有的话输出第一个没重复的字母的下标,都是重复的话就输出-1
Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.
Examples:
s = "leetcode"
return 0.
s = "loveleetcode",
return 2.
Note: You may assume the string contain only lowercase letters.
int firstUniqChar(char* s) {
int i=0,j=0;
int len=strlen(s);
int freq[26];
for(i=0;i<26;i++){
freq[i]=0;
}
for(i=0;i<len;i++){
freq[s[i]-'a']++;
}
for(i=0;i<len;i++){
if(freq[s[i]-'a']==1){
return i;
}
}
return -1;
}