java codility training Genomic-range-query

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

    Here is my solution. Got %100 . Of course I needed to first check and study a little bit prefix sums.

    public int[] solution(String S, int[] P, int[] Q){
    
            int[] result = new int[P.length];
    
            int[] factor1 = new int[S.length()];
            int[] factor2 = new int[S.length()];
            int[] factor3 = new int[S.length()];
            int[] factor4 = new int[S.length()];
    
            int factor1Sum = 0;
            int factor2Sum = 0;
            int factor3Sum = 0;
            int factor4Sum = 0;
    
            for(int i=0; i 0){
                        result[i] = 1;
                    }else if(factor2[end] > 0){
                        result[i] = 2;
                    }else if(factor3[end] > 0){
                        result[i] = 3;
                    }else{
                        result[i] = 4;
                    }
                }else{
                    if(factor1[end] > factor1[start-1]){
                        result[i] = 1;
                    }else if(factor2[end] > factor2[start-1]){
                        result[i] = 2;
                    }else if(factor3[end] > factor3[start-1]){
                        result[i] = 3;
                    }else{
                        result[i] = 4;
                    }
                }
    
            }
    
            return result;
        }
    

提交回复
热议问题