C++ beats 98.77% submission use Hash


  • 0
    B
    int firstUniqChar(string s) {
        int a[256] = {0};
        for(int i =0;s[i] != '\0';i++)
            a[s[i]]++;
        for(int i = 0;s[i] != '\0';i++)
            if(a[s[i]] == 1) return i;
        return -1;
    }

Log in to reply
 

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