문제
Build an n × n multiplication table: the value in row i, column j (both counting from 1) is i × j.
Implement multiplication_grid(n).
Input
n: The table size.
Output
Return the table as a list of rows.
제약 조건
0 ≤ n ≤ 20
예시
예시 1
입력:
n = 3
예상 출력:
expected = [
[1, 2, 3],
[2, 4, 6],
[3, 6, 9]
]
입력:
long long n = 3;
예상 출력:
std::vector<std::vector<long long>> expected = {
{1, 2, 3},
{2, 4, 6},
{3, 6, 9}
};
입력:
long n = 3;
예상 출력:
long[][] expected = new long[][] {
new long[] {1, 2, 3},
new long[] {2, 4, 6},
new long[] {3, 6, 9}
};
설명
Rows are [1, 2, 3], [2, 4, 6] and [3, 6, 9].
예시 2
입력:
n = 1
예상 출력:
expected = [
[1]
]
입력:
long long n = 1;
예상 출력:
std::vector<std::vector<long long>> expected = {
{1}
};
입력:
long n = 1;
예상 출력:
long[][] expected = new long[][] {
new long[] {1}
};
설명
A 1×1 table holds only 1 × 1 = 1.
접근 방법
먼저 스스로 풀어 본 뒤 힌트를 하나씩 열어 보세요.
힌트 1
각 칸은 행 번호와 열 번호를 곱한 값입니다.
힌트 2
표를 행 단위로 만들고, 각 행은 왼쪽에서 오른쪽으로 채우세요.
힌트 3
크기가 0이면 한 개의 빈 행이 아니라 빈 표를 반환하세요.
예상 복잡도
시간 O(n^2), 추가 공간 O(n^2)
참고 자료
이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.