Đề bài
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!".
Ràng buộc
0 ≤ start ≤ 1,000
Ví dụ
Đầu vào:
start = 3
Kết quả mong đợi:
expected = ["3", "2", "1", "Liftoff!"]
Đầu vào:
long long start = 3;
Kết quả mong đợi:
std::vector<std::string> expected = {"3", "2", "1", "Liftoff!"};
Đầu vào:
long start = 3;
Kết quả mong đợi:
string[] expected = new string[] {"3", "2", "1", "Liftoff!"};
Giải thích
"3", "2", "1", then "Liftoff!".
Đầu vào:
start = 0
Kết quả mong đợi:
expected = ["Liftoff!"]
Đầu vào:
long long start = 0;
Kết quả mong đợi:
std::vector<std::string> expected = {"Liftoff!"};
Đầu vào:
long start = 0;
Kết quả mong đợi:
string[] expected = new string[] {"Liftoff!"};
Giải thích
There is nothing to count, so only "Liftoff!" remains.
Hướng tiếp cận
Hãy tự thử trước, sau đó mở từng gợi ý một.
Gợi ý 1
Build the list by stepping downward from the starting number until you reach 1.
Gợi ý 2
Generate each entry as text, then append the final farewell message at the end.
Gợi ý 3
Remember the smallest input can skip the numeric loop and still return only the farewell.
Độ phức tạp mong đợi
O(start) time, O(start) extra space
Tham khảo
Thử thách này đã được điều chỉnh cho CodeUtility. Hãy làm theo đề bài và các ràng buộc ở trên.