Đề bài
Xem bản dịchBuild 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.
Ràng buộc
0 ≤ rows ≤ 30
Ví dụ
Ví dụ 1
Đầu vào:
rows = 3
Kết quả mong đợi:
expected = [
[1],
[1, 2],
[1, 2, 3]
]
Đầu vào:
long long rows = 3;
Kết quả mong đợi:
std::vector<std::vector<long long>> expected = {
{1},
{1, 2},
{1, 2, 3}
};
Đầu vào:
long rows = 3;
Kết quả mong đợi:
long[][] expected = new long[][] {
new long[] {1},
new long[] {1, 2},
new long[] {1, 2, 3}
};
Giải thích
Rows are [1], [1, 2] and [1, 2, 3].
Ví dụ 2
Đầu vào:
rows = 0
Kết quả mong đợi:
expected = []
Đầu vào:
long long rows = 0;
Kết quả mong đợi:
std::vector<std::vector<long long>> expected = {};
Đầu vào:
long rows = 0;
Kết quả mong đợi:
long[][] expected = new long[][] {};
Giải thích
No rows were requested, so the triangle is empty.
Tham khảo
Thử thách này đã được điều chỉnh cho CodeUtility. Hãy làm theo đề bài và các ràng buộc ở trên.