【leetcode】字符串中的第一个唯一字符

 

int firstUniqChar(char * s){
    int hash[128]={0},i,len=strlen(s);
    for (i=0; i<len; i++) 
        hash[s[i]]++;

    for (i=0; i<len; i++)
        if (hash[s[i]] == 1) return i;

    return -1;
}

 

posted @ 2020-09-28 11:39  温暖了寂寞  阅读(135)  评论(0编辑  收藏  举报