typedef struct{ int hash[4]; }st; int judge(char* s,int start,st* arr,int* size,int* map){ int i, add=0; for (i=start; i<start+10; i++){ if(arr[add].hash[map[s[i]-'A']]){ add=arr[add].hash[map[s[i]-'A']]; } else{ arr[add].hash[map[s[i]-'A']]=++(*size); add=*size; } } return add; } char ** findRepeatedDnaSequences(char * s, int* returnSize){ int len=strlen(s), i, size=0, cnt; char** ret=(char**)calloc(len,sizeof(char*)); st* arr=(st*)calloc(len*10+1,sizeof(st)); int* hash=(int*)calloc(len*10,sizeof(int)); int map[20]={0}; map['C'-'A']=1; map['G'-'A']=2; map['T'-'A']=3; *returnSize=0; for (i=0; i+9<len; i++){ cnt = judge(s,i,arr,&size,map); if(hash[cnt]++==1){ char* temp=(char*)calloc(11,sizeof(char)); memcpy(temp,s+i,sizeof(char)*10); ret[(*returnSize)++]=temp; } } return ret; }