쉬움 0명 해결 정답률 0%

Pyramid Rows

Draw a right-aligned pyramid of # blocks.

배우게 될 내용

  • 여백과 블록으로 행 만들기
  • 행마다 공백과 기호 수 계산하기
  • 줄을 리스트로 반환하기

문제

Draw a right-aligned pyramid like the one in Super Mario: row i (counting from 1) has height − i spaces followed by i # characters.

Implement pyramid_rows(height).

Input

height: The number of rows.

Output

Return the rows from top to bottom.

제약 조건

0 ≤ height ≤ 50

예시

예시 1
입력:
height = 3

예상 출력:
expected = ["  #", " ##", "###"]
입력:
long long height = 3;

예상 출력:
std::vector<std::string> expected = {"  #", " ##", "###"};
입력:
long height = 3;

예상 출력:
string[] expected = new string[] {"  #", " ##", "###"};

설명

Rows are " #", " ##" and "###": each row has one more block and one less space.

예시 2
입력:
height = 1

예상 출력:
expected = ["#"]
입력:
long long height = 1;

예상 출력:
std::vector<std::string> expected = {"#"};
입력:
long height = 1;

예상 출력:
string[] expected = new string[] {"#"};

설명

A single row with one block: "#".

접근 방법

먼저 스스로 풀어 본 뒤 힌트를 하나씩 열어 보세요.

힌트 1

각 줄은 앞의 공백과 점점 늘어나는 # 문자 묶음으로 구성됩니다.

힌트 2

위에서 아래로 한 줄씩 만들면 정렬이 정확하게 유지됩니다.

힌트 3

높이가 0이면 빈 피라미드처럼 보이는 것이 아니라 행이 없는 결과를 반환하세요.

예상 복잡도

시간 O(height^2), 추가 공간 O(height^2)

참고 자료

이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.

다른 사람의 풀이 보기

커뮤니티 솔루션

아직 공개된 풀이가 없습니다. 문제를 풀고 첫 풀이를 공유하세요.