java codility training Genomic-range-query

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

    This is my JavaScript solution that got 100% across the board on Codility:

    function solution(S, P, Q) {
        let total = [];
        let min;
    
        for (let i = 0; i < P.length; i++) {
            const substring = S.slice(P[i], Q[i] + 1);
            if (substring.includes('A')) {
                min = 1;
            } else if (substring.includes('C')) {
                min = 2;
            } else if (substring.includes('G')) {
                min = 3;
            } else if (substring.includes('T')) {
                min = 4;
            }
            total.push(min);
        }
        return total;
    }
    

提交回复
热议问题