문제
번역본 보기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.
예시
입력:
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.
입력:
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에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.