Problema
Mostra traduzioneBuild a number triangle: row i (counting from 1) lists the numbers 1, 2, …, i.
Implement number_triangle(rows).
Input
rows: The number of rows.
Output
Return the triangle as a list of rows.
Vincoli
0 ≤ rows ≤ 30
Esempi
Esempio 1
Input:
rows = 3
Output atteso:
expected = [
[1],
[1, 2],
[1, 2, 3]
]
Input:
long long rows = 3;
Output atteso:
std::vector<std::vector<long long>> expected = {
{1},
{1, 2},
{1, 2, 3}
};
Input:
long rows = 3;
Output atteso:
long[][] expected = new long[][] {
new long[] {1},
new long[] {1, 2},
new long[] {1, 2, 3}
};
Spiegazione
Rows are [1], [1, 2] and [1, 2, 3].
Esempio 2
Input:
rows = 0
Output atteso:
expected = []
Input:
long long rows = 0;
Output atteso:
std::vector<std::vector<long long>> expected = {};
Input:
long rows = 0;
Output atteso:
long[][] expected = new long[][] {};
Spiegazione
No rows were requested, so the triangle is empty.
Riferimenti
Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.