Problem
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.
Einschränkungen
0 ≤ height ≤ 50
Beispiele
Eingabe:
height = 3
Erwartete Ausgabe:
expected = [" #", " ##", "###"]
Eingabe:
long long height = 3;
Erwartete Ausgabe:
std::vector<std::string> expected = {" #", " ##", "###"};
Eingabe:
long height = 3;
Erwartete Ausgabe:
string[] expected = new string[] {" #", " ##", "###"};
Erläuterung
Rows are " #", " ##" and "###": each row has one more block and one less space.
Eingabe:
height = 1
Erwartete Ausgabe:
expected = ["#"]
Eingabe:
long long height = 1;
Erwartete Ausgabe:
std::vector<std::string> expected = {"#"};
Eingabe:
long height = 1;
Erwartete Ausgabe:
string[] expected = new string[] {"#"};
Erläuterung
A single row with one block: "#".
So gehst du vor
Versuch es zuerst allein und öffne dann einen Hinweis nach dem anderen.
Hinweis 1
Each row combines leading spaces with a growing run of hash characters.
Hinweis 2
Build rows one by one from top to bottom so the alignment stays correct.
Hinweis 3
If the height is zero, return no rows rather than an empty-looking pyramid.
Erwartete Komplexität
O(height^2) time, O(height^2) extra space
Referenzen
Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.