문제
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
예시
입력:
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.
입력:
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
Each row combines leading spaces with a growing run of hash characters.
힌트 2
Build rows one by one from top to bottom so the alignment stays correct.
힌트 3
If the height is zero, return no rows rather than an empty-looking pyramid.
예상 복잡도
O(height^2) time, O(height^2) extra space
참고 자료
이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제약 조건을 기준으로 풀어 주세요.