모든 챌린지
쉬움 3명 해결 정답률 100.0%

Countdown to Liftoff

Count down from a number and end with Liftoff!

배우게 될 내용

  • Count down with a loop
  • Mix numbers and text in a list
  • Stop at the right value

문제

번역본 보기

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

예시

예시 1
입력:
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!".

예시 2
입력:
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

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에 맞게 수정되었습니다. 위의 설명과 제약 조건을 기준으로 풀어 주세요.

코더마다 가장 좋은 통과 풀이입니다. 더 빠르고, 메모리를 덜 쓰고, 평가가 좋은 풀이가 위에 옵니다.

# 코더 언어 시간 메모리 AI 평가 풀이
1 RCRiccardo Corti Python 700 ms - 5/5 코드 보기
2 HJhettory Jurash Python 712 ms - 5/5 코드 보기
3 LMLaura Mahlow Python 722 ms - 5/5 코드 보기

다른 사람의 풀이 보기

커뮤니티 풀이

스포일러: 아래에 전체 풀이 3개가 있습니다 먼저 직접 풀어보세요. 다른 개발자의 코드와 AI 리뷰도 참고할 수 있습니다. 로그인하고 문제를 풀면 토론에 참여할 수 있습니다.