java codility training Genomic-range-query

后端 未结 30 2262
悲哀的现实
悲哀的现实 2021-02-01 12:47

The task is:

A non-empty zero-indexed string S is given. String S consists of N characters from the set of upper-case English letters A, C, G, T.

<
30条回答
  •  孤城傲影
    2021-02-01 13:48

    /* 100/100 solution C++. Using prefix sums. Firstly converting chars to integer in nuc variable. Then in a bi-dimensional vector we account the occurrence in S of each nucleoside x in it's respective prefix_sum[s][x]. After we just have to find out the lower nucluoside that occurred in each interval K.

    */ . vector solution(string &S, vector &P, vector &Q) {

    int n=S.size();
    int m=P.size();
    vector > prefix_sum(n+1,vector(4,0));
    int nuc;
    
    //prefix occurrence sum
    for (int s=0;s=0;u--) {
            if (prefix_sum[Q[k]+1][u] - prefix_sum[P[k]][u] != 0)
                lower_impact_factor = u+1;
        }
        P[k]=lower_impact_factor;
    }
    
    return P;
    

    }

提交回复
热议问题