Легко Решено: 0 Процент решений: 0%

Pascal’s Triangle

Build rows by adding neighboring entries from the previous row.

The first row is [1]. Each later row starts and ends with 1. Every interior entry is the sum of the two entries immediately above it. Return the first rows rows, beginning with the single 1.

Implement pascals_triangle(rows).

Input

rows: How many rows to generate.

Output

Return a list of rows, starting at the top; each row is a list of integers.

Ограничения

0 ≤ rows ≤ 60. Every entry fits a signed 64-bit integer. Zero rows returns an empty list.

Примеры

Пример 1
Ввод:
rows = 4

Ожидаемый вывод:
expected = [
    [1],
    [1, 1],
    [1, 2, 1],
    [1, 3, 3, 1]
]
Ввод:
long long rows = 4;

Ожидаемый вывод:
std::vector<std::vector<long long>> expected = {
    {1},
    {1, 1},
    {1, 2, 1},
    {1, 3, 3, 1}
};
Ввод:
long rows = 4;

Ожидаемый вывод:
long[][] expected = new long[][] {
    new long[] {1},
    new long[] {1, 1},
    new long[] {1, 2, 1},
    new long[] {1, 3, 3, 1}
};

Пояснение

The 2 in row 3 is 1 + 1. The two interior 3s in row 4 are 1 + 2 and 2 + 1.

Пример 2
Ввод:
rows = 0

Ожидаемый вывод:
expected = []
Ввод:
long long rows = 0;

Ожидаемый вывод:
std::vector<std::vector<long long>> expected = {};
Ввод:
long rows = 0;

Ожидаемый вывод:
long[][] expected = new long[][] {};

Пояснение

No rows are requested, so return an empty list.

Ссылки

Это задание адаптировано для CodeUtility. Следуйте условию и ограничениям выше.

Учитесь у других

Решения сообщества

Пока нет опубликованных решений. Решите задание, чтобы поделиться первым.