문제
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에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.