I notice it seems that few people use c to write code. it's my share (0ms).C code,explanation online


  • 0
    Y
    char** findRepeatedDnaSequences(char* s, int* returnSize) {
        int len=strlen(s);
        char** result=(char**)malloc(sizeof(char*)*(len-10));
        *returnSize=0;
        unsigned char map[1024*256];
        memset(map,0,sizeof(char)*1024*256);
        unsigned int i,sum=0,store;
        for(i=0;i<9;i++)
                sum=(sum<<2)|((s[i]&0x6)>>1);
        store = (s[9]&0x6)>>1;
        map[sum]=(0x4<<store)|map[sum];
        map[sum]|=0x1;
        for(i=10;i<len;i++){
                sum=((sum&0xffff)<<2)|store;
                store=(s[i]&0x6)>>1;
                int temp=(map[sum])^(0x4<<store);
                if(temp==1){
                        result[*returnSize]=(char*)malloc(sizeof(char)*11);
                        strncpy(result[*returnSize],s+i-9,10);
                        result[*returnSize][10]=0;
                        (*returnSize)++;
                        map[sum]=map[sum]|0x2;
                }
                else if(temp==2)                {
                        continue;
                }
                else {
                        map[sum]=(0x4<<store)|map[sum];
                        map[sum]|=0x1;
                }
        }
        return result;
       }

Log in to reply
 

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