探しています:
文字列を指定して、最初の一意の文字を見つけ、そのインデックスを返します。存在しない場合は-1を返します。
ケース:
s = "leetcode"
は0を返します。
s = "loveleetcode"、
2を返します。
注:文字列には小文字のみが含まれていると想定できます。
解決策:
#define MAXSIZE 26
int firstUniqChar(char * s){
int hashTable [MAXSIZE] = {0};
char * tmp;
intインデックス;
int count = 0;
for(tmp = s; * tmp!= '\ 0'; tmp ++){
インデックス= * tmp-'a';
hashTable [index] ++;
}
for(tmp = s; * tmp!= '\ 0'; tmp ++){
インデックス= * tmp-'a';
if(hashTable [index] == 1)はカウントを返します。
count ++;
}
リターン-1;
}