Easy C solution 9ms


  • 0
    int firstUniqChar(char* s) {
        int charCount[256] = {0};
        int index = 0;
        char tmp;
        while((tmp=s[index])!=0){
            charCount[tmp] ++;
            index++;
        }
        index = 0;
        while((tmp=s[index])!=0){
            if(charCount[tmp]==1) return index;
            index ++;
        }
        return -1;
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.