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");
    } 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值