18. 4Sum
This commit is contained in:
40
18. 4Sum/Program.cs
Normal file
40
18. 4Sum/Program.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
var sol = new Solution();
|
||||
|
||||
var cases = new (int[] nums, int target, int[][] expected)[]
|
||||
{
|
||||
// (new[] { 1, 0, -1, 0, -2, 2 }, 0, new[]
|
||||
// {
|
||||
// new[] { -2, -1, 1, 2 },
|
||||
// new[] { -2, 0, 0, 2 },
|
||||
// new[] { -1, 0, 0, 1 }
|
||||
// }),
|
||||
// (new[] { 2, 2, 2, 2, 2 }, 8, new[]
|
||||
// {
|
||||
// new[] { 2, 2, 2, 2 }
|
||||
// }),
|
||||
// (new[] { -3, -1, 0, 2, 4, 5 }, 2, new[]
|
||||
// {
|
||||
// new[] { -3, -1, 2, 4 }
|
||||
// }),
|
||||
(new[] { 1000000000, 1000000000, 1000000000, 1000000000 }, -294967296, Array.Empty<int[]>())
|
||||
};
|
||||
|
||||
foreach (var (nums, target, expected) in cases)
|
||||
{
|
||||
var actual = sol.FourSum(nums, target);
|
||||
Console.WriteLine($"nums={FormatArray(nums)}, target={target} -> {FormatResults(actual)} (expected: {FormatResults(expected)})");
|
||||
}
|
||||
|
||||
static string FormatArray(int[] nums)
|
||||
{
|
||||
return $"[{string.Join(",", nums)}]";
|
||||
}
|
||||
|
||||
static string FormatResults(IList<IList<int>> results)
|
||||
{
|
||||
return "[" + string.Join(",", results.Select(r => $"[{string.Join(",", r)}]")) + "]";
|
||||
}
|
||||
Reference in New Issue
Block a user