Problème
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.
Contraintes
0 ≤ n ≤ 20
Exemples
Exemple 1
Entrée :
n = 3
Sortie attendue :
expected = [
[1, 2, 3],
[2, 4, 6],
[3, 6, 9]
]
Entrée :
long long n = 3;
Sortie attendue :
std::vector<std::vector<long long>> expected = {
{1, 2, 3},
{2, 4, 6},
{3, 6, 9}
};
Entrée :
long n = 3;
Sortie attendue :
long[][] expected = new long[][] {
new long[] {1, 2, 3},
new long[] {2, 4, 6},
new long[] {3, 6, 9}
};
Explication
Rows are [1, 2, 3], [2, 4, 6] and [3, 6, 9].
Exemple 2
Entrée :
n = 1
Sortie attendue :
expected = [
[1]
]
Entrée :
long long n = 1;
Sortie attendue :
std::vector<std::vector<long long>> expected = {
{1}
};
Entrée :
long n = 1;
Sortie attendue :
long[][] expected = new long[][] {
new long[] {1}
};
Explication
A 1×1 table holds only 1 × 1 = 1.
Références
Ce défi a été adapté pour CodeUtility. Suivez l'énoncé et les contraintes ci-dessus.