codewars解题笔记---DNA to RNA Conversion

题目

Deoxyribonucleic acid, DNA is the primary information storage molecule in biological systems. It is composed of four nucleic acid bases Guanine ('G'), Cytosine ('C'), Adenine ('A'), and Thymine ('T').

Ribonucleic acid, RNA, is the primary messenger molecule in cells. RNA differs slightly from DNA its chemical structure and contains no Thymine. In RNA Thymine is replaced by another nucleic acid Uracil ('U').

Create a funciton which translates a given DNA string into RNA.

For example:

new Bio().dnaToRna("GCAT") // returns "GCAU"

The input string can be of arbitrary length - in particular, it may be empty. All input is guaranteed to be valid, i.e. each input string will only ever consist of 'G''C''A' and/or 'T'.

解析

脱氧核糖核酸是生物系统中主要的信息存储分子。由四种核酸碱基鸟嘌呤(G’)、胞嘧啶(C’)、腺嘌呤(A’)和胸腺嘧啶(T’)组成。

核糖核酸是细胞中的主要信使分子。RNA与DNA的化学结构稍有不同,不含胸腺嘧啶。在RNA中,胸腺嘧啶被另一种核酸尿嘧啶(“U”)取代。

创建一个功能,将给定的DNA字符串转换成RNA。

输入字符串可以是任意长度,尤其是可以是空的。所有输入均保证有效,即每个输入字符串仅由'G'、'C'、'A'和/或'T'组成。

功能解析

传入一个字符串,将字符串中U转换为T

我的答案

    public String dnaToRna(String dna) {
      String str = dna.replaceAll("T","U");
      return str;  // Do your magic!
    } 

最好的解决

  public String dnaToRna(String dna){
        return dna.replace("T", "U");
    } 

猜你喜欢

转载自blog.csdn.net/z_victoria123/article/details/86535329
今日推荐