Problem
The right triangle is usually the first pattern program in an intro course: row 1 has one *, row 2 has two, and so on down to row n. The outer loop picks the row and the inner loop (or string repetition) builds it.
Implement right_triangle_stars(n).
Input
n: The number of rows.
Output
Return the rows from top to bottom. Row i (counting from 1) is i * characters with no spaces.
Einschränkungen
0 ≤ n ≤ 100
Beispiele
Eingabe:
n = 3
Erwartete Ausgabe:
expected = ["*", "**", "***"]
Eingabe:
long long n = 3;
Erwartete Ausgabe:
std::vector<std::string> expected = {"*", "**", "***"};
Eingabe:
long n = 3;
Erwartete Ausgabe:
string[] expected = new string[] {"*", "**", "***"};
Erläuterung
Rows grow by one star: "*", "**", "***".
Eingabe:
n = 1
Erwartete Ausgabe:
expected = ["*"]
Eingabe:
long long n = 1;
Erwartete Ausgabe:
std::vector<std::string> expected = {"*"};
Eingabe:
long n = 1;
Erwartete Ausgabe:
string[] expected = new string[] {"*"};
Erläuterung
A single row with one star: ["*"].
So gehst du vor
Versuch es zuerst allein und öffne dann einen Hinweis nach dem anderen.
Hinweis 1
Row i needs exactly i stars, so the row number is all you need.
Hinweis 2
Repeat the star character instead of adding one character at a time if your language allows it.
Hinweis 3
When n is 0, return an empty list.
Erwartete Komplexität
O(n^2) time, O(n^2) extra space
Referenzen
Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.