java codility training Genomic-range-query

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

    Hope this helps.

    public int[] solution(String S, int[] P, int[] K) {
            // write your code in Java SE 8
            char[] sc = S.toCharArray();
            int[] A = new int[sc.length];
            int[] G = new int[sc.length];
            int[] C = new int[sc.length];
    
            int prevA =-1,prevG=-1,prevC=-1;
    
            for(int i=0;i=P[i] && A[K[i]] <=K[i]){
                      result[i] =1;
                }
                else if(C[K[i]] >=P[i] && C[K[i]] <=K[i]){
                      result[i] =2;
                }else if(G[K[i]] >=P[i] && G[K[i]] <=K[i]){
                      result[i] =3;
                }
                else{
                    result[i]=4;
                }
            }
    
            return result;
        }
    

提交回复
热议问题