2906. Construct Product Matrix
This commit is contained in:
@@ -1,2 +1,74 @@
|
||||
// See https://aka.ms/new-console-template for more information
|
||||
Console.WriteLine("Hello, World!");
|
||||
static string FormatMatrix(int[][] matrix)
|
||||
{
|
||||
var rows = new string[matrix.Length];
|
||||
for (var i = 0; i < matrix.Length; i++)
|
||||
rows[i] = "[" + string.Join(",", matrix[i]) + "]";
|
||||
return "[" + string.Join(",", rows) + "]";
|
||||
}
|
||||
|
||||
var sol = new Solution();
|
||||
|
||||
var cases = new (int[][] input, string expected)[]
|
||||
{
|
||||
(
|
||||
new[]
|
||||
{
|
||||
new[] { 1, 2 },
|
||||
new[] { 3, 4 }
|
||||
},
|
||||
"[[24,12],[8,6]]"
|
||||
),
|
||||
(
|
||||
new[]
|
||||
{
|
||||
new[] { 12345 },
|
||||
new[] { 2 },
|
||||
new[] { 1 }
|
||||
},
|
||||
"[[2],[0],[0]]"
|
||||
),
|
||||
(
|
||||
new[]
|
||||
{
|
||||
new[] { 4, 8, 8 },
|
||||
new[] { 6, 2, 5 },
|
||||
new[] { 7, 3, 7 },
|
||||
new[] { 6, 3, 5 }
|
||||
},
|
||||
"[[3525,7935,7935],[6465,7050,2820],[7305,585,7305],[6465,585,2820]]"
|
||||
),
|
||||
(
|
||||
new[]
|
||||
{
|
||||
new[] { 4, 3, 9 },
|
||||
new[] { 3, 9, 10 },
|
||||
new[] { 9, 7, 8 },
|
||||
new[] { 8, 4, 7 },
|
||||
new[] { 6, 1, 3 }
|
||||
},
|
||||
"[[3255,225,75],[225,75,11178],[75,1860,7800],[7800,3255,1860],[6285,675,225]]"
|
||||
),
|
||||
(
|
||||
new[]
|
||||
{
|
||||
new []{1,2,2},
|
||||
new []{1,4,3}
|
||||
},
|
||||
"[[48,24,24],[48,12,16]]"
|
||||
),
|
||||
(
|
||||
new[]
|
||||
{
|
||||
new[] { 414750857 },
|
||||
new[] { 449145368 },
|
||||
new[] { 767292749 }
|
||||
},
|
||||
"[[1462],[3103],[9436]]"
|
||||
)
|
||||
};
|
||||
|
||||
foreach (var (input, expected) in cases)
|
||||
{
|
||||
var actual = sol.ConstructProductMatrix(input);
|
||||
Console.WriteLine($"{FormatMatrix(input)} -> {FormatMatrix(actual)} (expected: {expected})");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user