mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-13 02:38:34 +08:00
Add build script for JS and TS codes.
This commit is contained in:
@ -8,10 +8,10 @@ using NUnit.Framework;
|
||||
|
||||
namespace hello_algo.chapter_computational_complexity
|
||||
{
|
||||
/* 方法一:暴力枚举 */
|
||||
class SolutionBruteForce
|
||||
public class leetcode_two_sum
|
||||
{
|
||||
public int[] twoSum(int[] nums, int target)
|
||||
/* 方法一:暴力枚举 */
|
||||
public static int[] twoSumBruteForce(int[] nums, int target)
|
||||
{
|
||||
int size = nums.Length;
|
||||
// 两层循环,时间复杂度 O(n^2)
|
||||
@ -25,12 +25,9 @@ namespace hello_algo.chapter_computational_complexity
|
||||
}
|
||||
return new int[0];
|
||||
}
|
||||
}
|
||||
|
||||
/* 方法二:辅助哈希表 */
|
||||
class SolutionHashMap
|
||||
{
|
||||
public int[] twoSum(int[] nums, int target)
|
||||
/* 方法二:辅助哈希表 */
|
||||
public static int[] twoSumHashTable(int[] nums, int target)
|
||||
{
|
||||
int size = nums.Length;
|
||||
// 辅助哈希表,空间复杂度 O(n)
|
||||
@ -46,10 +43,7 @@ namespace hello_algo.chapter_computational_complexity
|
||||
}
|
||||
return new int[0];
|
||||
}
|
||||
}
|
||||
|
||||
public class leetcode_two_sum
|
||||
{
|
||||
[Test]
|
||||
public void Test()
|
||||
{
|
||||
@ -59,13 +53,11 @@ namespace hello_algo.chapter_computational_complexity
|
||||
|
||||
// ====== Driver Code ======
|
||||
// 方法一
|
||||
SolutionBruteForce slt1 = new SolutionBruteForce();
|
||||
int[] res = slt1.twoSum(nums, target);
|
||||
int[] res = twoSumBruteForce(nums, target);
|
||||
Console.WriteLine("方法一 res = " + string.Join(",", res));
|
||||
// 方法二
|
||||
SolutionHashMap slt2 = new SolutionHashMap();
|
||||
res = slt2.twoSum(nums, target);
|
||||
res = twoSumHashTable(nums, target);
|
||||
Console.WriteLine("方法二 res = " + string.Join(",", res));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user