C Solution in 40ms


  • 0
    R
    int maxProduct(char** s, int wS) {
        int i, j, k, *a[2], p, maxp=0;
        a[0] = malloc(sizeof(int)*wS);
        a[1] = malloc(sizeof(int)*wS);
        for(i=0; i<wS; i++)
        {
            a[0][i]=0;
            for(j=0, p=strlen(s[i]); j<p; j++)
                a[0][i] = a[0][i] | (1<<(s[i][j]-'a')) ;
            a[1][i]=p;
            for(k=0; k<i; k++)
            {
                if((a[0][i] & a[0][k]) == 0)
                {
                    p = a[1][i] * a[1][k];
                    maxp = p>maxp ? p : maxp ;
                }
            }`enter code here`
            //printf("%d.max = %d\n", i, maxp);
        }
        free(a[0]);
        free(a[1]);
        return maxp;
    }

Log in to reply
 

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