java codility training Genomic-range-query

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

    Here's 100% Scala solution:

    def solution(S: String, P: Array[Int], Q: Array[Int]): Array[Int] = {
    
    
        val resp = for(ind <- 0 to P.length-1) yield {
    
          val sub= S.substring(P(ind),Q(ind)+1)
    
    
          var factor = 4
    
          if(sub.contains("A")) {factor=1}
          else{
            if(sub.contains("C")) {factor=2}
            else{
              if(sub.contains("G")) {factor=3}
            }
          }
          factor
    
        }
    
        return resp.toArray
    
      }
    

    And performance: https://codility.com/demo/results/trainingEUR4XP-425/

提交回复
热议问题