First Unique Character in a String (C)


  • 0
    P
    int firstUniqChar(char* s) {
        int n, i=0, l = strlen(s);
        for ( i=0; i < l; i++ ) {
            n = 0;
            for( int j=0; j < l; j++) {
                if(s[i] == s[j]) 
                    n++;
                if(n > 1)
                  break;
            }
            if(n < 2)
                return i;
        }
        return -1;
    }

Log in to reply
 

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