Problème
Build 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.
Contraintes
0 ≤ rows ≤ 30
Exemples
Exemple 1
Entrée :
rows = 3
Sortie attendue :
expected = [
[1],
[1, 2],
[1, 2, 3]
]
Entrée :
long long rows = 3;
Sortie attendue :
std::vector<std::vector<long long>> expected = {
{1},
{1, 2},
{1, 2, 3}
};
Entrée :
long rows = 3;
Sortie attendue :
long[][] expected = new long[][] {
new long[] {1},
new long[] {1, 2},
new long[] {1, 2, 3}
};
Explication
Rows are [1], [1, 2] and [1, 2, 3].
Exemple 2
Entrée :
rows = 0
Sortie attendue :
expected = []
Entrée :
long long rows = 0;
Sortie attendue :
std::vector<std::vector<long long>> expected = {};
Entrée :
long rows = 0;
Sortie attendue :
long[][] expected = new long[][] {};
Explication
No rows were requested, so the triangle is empty.
Références
Ce défi a été adapté pour CodeUtility. Suivez l'énoncé et les contraintes ci-dessus.