Problem
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.
Constraints
0 ≤ rows ≤ 30
Examples
Example 1
Input:
rows = 3
Expected output:
expected = [
[1],
[1, 2],
[1, 2, 3]
]
Input:
long long rows = 3;
Expected output:
std::vector<std::vector<long long>> expected = {
{1},
{1, 2},
{1, 2, 3}
};
Input:
long rows = 3;
Expected output:
long[][] expected = new long[][] {
new long[] {1},
new long[] {1, 2},
new long[] {1, 2, 3}
};
Explanation
Rows are [1], [1, 2] and [1, 2, 3].
Example 2
Input:
rows = 0
Expected output:
expected = []
Input:
long long rows = 0;
Expected output:
std::vector<std::vector<long long>> expected = {};
Input:
long rows = 0;
Expected output:
long[][] expected = new long[][] {};
Explanation
No rows were requested, so the triangle is empty.
References
This challenge is adapted for CodeUtility. Follow the statement and constraints above.