c lines solution 12ms O(n)


  • 0
    G
    int firstUniqChar(char* s) {
        if(s == NULL || strlen(s) == 0) return -1;
        if(strlen(s) == 1) return 0;
    
        int dic[26] = {0},index = 0;
        char *c = s;
        while (*c != '\0') {
            dic[*c++ - 'a'] += 1;
        }
        
        while (*s != '\0') {
            if (dic[*s++ -'a'] == 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.