Update worst_best_time_complexity,

leetcode_two_sum
This commit is contained in:
Yudong Jin
2023-02-03 18:53:15 +08:00
parent 592965595e
commit 70dead5cd0
24 changed files with 63 additions and 121 deletions

View File

@ -8,6 +8,7 @@ using NUnit.Framework;
namespace hello_algo.chapter_computational_complexity
{
/* 方法一:暴力枚举 */
class SolutionBruteForce
{
public int[] twoSum(int[] nums, int target)
@ -26,6 +27,7 @@ namespace hello_algo.chapter_computational_complexity
}
}
/* 方法二:辅助哈希表 */
class SolutionHashMap
{
public int[] twoSum(int[] nums, int target)

View File

@ -37,6 +37,8 @@ namespace hello_algo.chapter_computational_complexity
{
for (int i = 0; i < nums.Length; i++)
{
// 当元素 1 在数组头部时,达到最佳时间复杂度 O(1)
// 当元素 1 在数组尾部时,达到最差时间复杂度 O(n)
if (nums[i] == 1)
return i;
}