簡単 1件解決済み 正答率100.0%

DNA to RNA Transcription

Build an RNA string by replacing every DNA character with its partner.

このチャレンジで学べること

  • Translate characters with a lookup table
  • Build a new string from mapped characters
  • Handle every character in a sequence

問題

翻訳を表示

Build an RNA string by replacing every DNA character with its partner. Use this complete mapping: A → U, C → G, G → C, T → A. Preserve the original order. No biology knowledge is needed.

Implement dna_to_rna(dna).

Input

dna: The DNA string to transform.

Output

Return the transformed string. Empty input returns an empty string.

制約

0 ≤ DNA length ≤ 100,000. Characters are uppercase A, C, G, or T.

例

例 1
入力:
dna = "ACGT"

期待される出力:
expected = "UGCA"
入力:
std::string dna = "ACGT";

期待される出力:
std::string expected = "UGCA";
入力:
string dna = "ACGT";

期待される出力:
string expected = "UGCA";

解説

A becomes U, C becomes G, G becomes C, and T becomes A, giving UGCA.

例 2
入力:
dna = ""

期待される出力:
expected = ""
入力:
std::string dna = "";

期待される出力:
std::string expected = "";
入力:
string dna = "";

期待される出力:
string expected = "";

解説

There are no characters to replace, so the result is empty.

解き方のヒント

まずは自分で考えてから、ヒントを1つずつ開いてみましょう。

ヒント 1

Each DNA letter maps to exactly one RNA letter, so translate character by character.

ヒント 2

Use a direct lookup for the four valid symbols while preserving the original order.

ヒント 3

An empty input should return an empty string, and every character is guaranteed to be valid.

目安の計算量

O(n) time, O(n) extra space

参考資料

この課題はCodeUtility用に調整されています。上記の説明と制約に従ってください。

ランキング

全体ランキング

コーダーごとのいちばん良い合格解答です。速く、メモリが少なく、評価が高い解答ほど上位になります。

# コーダー 言語 時間 メモリ AI 評価 解答
1 RCRiccardo Corti Python 870 ms - 5/5 コードを見る

他の人の解答から学ぶ

コミュニティの解答

ネタバレ注意: この下に解答が1件あります まずは自分で挑戦してみましょう。他の開発者のコードやAIレビューも見ることができます。 サインインして課題を解くと議論に参加できます。