모든 챌린지
쉬움 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에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.

다른 사람의 풀이 보기

커뮤니티 솔루션

아직 공개된 풀이가 없습니다. 문제를 풀고 첫 풀이를 공유하세요.