java codility training Genomic-range-query

后端 未结 30 2267
悲哀的现实
悲哀的现实 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:37

    Here's a simple javascript solution which got 100%.

    function solution(S, P, Q) {
        var A = [];
        var C = [];
        var G = [];
        var T = [];
        var result = [];
        var i = 0;
    
        S.split('').forEach(function(a) {
            if (a === 'A') {
                A.push(i);
            } else if (a === 'C') {
                C.push(i);
            } else if (a === 'G') {
                G.push(i);
            } else {
                T.push(i);
            }
    
            i++;
        });
    
        function hasNucl(typeArray, start, end) {
            return typeArray.some(function(a) {
                return a >= P[j] && a <= Q[j];
            });
        }
    
        for(var j=0; j

提交回复
热议问题