Fastest!Only 4ms C solution


  • 1
    B
    #include <string.h>
    #define _(X) (X<'G'?X>'A':2|(X>'G'))
    char l[1048576];
    char** findRepeatedDnaSequences(char* s, int* returnSize) {
    	char *p,**r;
    	int n = 0, i, x, Z = (1 << 20) - 1, len;
    	memset(l,0,sizeof(l));
    	if ((len = strlen(s)) < 11) goto end;
    	
    	r = (char**)malloc(sizeof(char*)*len>>5);
    	for (x = i = 0; i < 10; i++) x = (x << 2) | _(s[i]);
    	for (p = s + 10; *(p-1);p++){
    		if (!l[x]) l[x]++;
    		else if (l[x] > 0){
    			r[n] = (char*)malloc(sizeof(char)*11);
    			for (i = 0; i < 10; i++) r[n][i] = i[p - 10];
    			r[n++][10] = '\0';
    			l[x] = -1;
    		}
    		x = ((x << 2) | _(*p))&Z;
    	}
    end:;
    	*returnSize = n;
    	return r;
    }

  • 0
    L

    very talent, 10-letter-long string with each letter is in range of (A,C,G,T) discretely, make it 1M probabilities . Using a 1M-sized array can solve the problem. Thank you!


  • -2

Log in to reply
 

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