問題
Count down from start to 1, then add "Liftoff!". Each number becomes one text entry.
Implement countdown(start).
Input
start: The number to start counting down from.
Output
Return the countdown as a list of strings, ending with "Liftoff!".
制約
0 ≤ start ≤ 1,000
例
入力:
start = 3
期待される出力:
expected = ["3", "2", "1", "Liftoff!"]
入力:
long long start = 3;
期待される出力:
std::vector<std::string> expected = {"3", "2", "1", "Liftoff!"};
入力:
long start = 3;
期待される出力:
string[] expected = new string[] {"3", "2", "1", "Liftoff!"};
解説
"3", "2", "1", then "Liftoff!".
入力:
start = 0
期待される出力:
expected = ["Liftoff!"]
入力:
long long start = 0;
期待される出力:
std::vector<std::string> expected = {"Liftoff!"};
入力:
long start = 0;
期待される出力:
string[] expected = new string[] {"Liftoff!"};
解説
There is nothing to count, so only "Liftoff!" remains.
解き方のヒント
まずは自分で考えてから、ヒントを 1 つずつ開いてみましょう。
ヒント 1
Build the list by stepping downward from the starting number until you reach 1.
ヒント 2
Generate each entry as text, then append the final farewell message at the end.
ヒント 3
Remember the smallest input can skip the numeric loop and still return only the farewell.
目安の計算量
O(start) time, O(start) extra space
参考資料
この課題はCodeUtility用に調整されています。上記の説明と制約に従ってください。