mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-10 14:36:06 +00:00
feat(csharp) .NET 8.0 code migration (#966)
* .net 8.0 migration * update docs * revert change * revert change and update appendix docs * remove static * Update binary_search_insertion.cs * Update binary_search_insertion.cs * Update binary_search_edge.cs * Update binary_search_insertion.cs * Update binary_search_edge.cs --------- Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
@@ -8,7 +8,7 @@ namespace hello_algo.chapter_searching;
|
||||
|
||||
public class binary_search_insertion {
|
||||
/* 二分查找插入点(无重复元素) */
|
||||
public int BinarySearchInsertionSimple(int[] nums, int target) {
|
||||
public static int BinarySearchInsertionSimple(int[] nums, int target) {
|
||||
int i = 0, j = nums.Length - 1; // 初始化双闭区间 [0, n-1]
|
||||
while (i <= j) {
|
||||
int m = i + (j - i) / 2; // 计算中点索引 m
|
||||
@@ -44,7 +44,7 @@ public class binary_search_insertion {
|
||||
[Test]
|
||||
public void Test() {
|
||||
// 无重复元素的数组
|
||||
int[] nums = { 1, 3, 6, 8, 12, 15, 23, 26, 31, 35 };
|
||||
int[] nums = [1, 3, 6, 8, 12, 15, 23, 26, 31, 35];
|
||||
Console.WriteLine("\n数组 nums = " + nums.PrintList());
|
||||
// 二分查找插入点
|
||||
foreach (int target in new int[] { 6, 9 }) {
|
||||
@@ -53,7 +53,7 @@ public class binary_search_insertion {
|
||||
}
|
||||
|
||||
// 包含重复元素的数组
|
||||
nums = new int[] { 1, 3, 6, 6, 6, 6, 6, 10, 12, 15 };
|
||||
nums = [1, 3, 6, 6, 6, 6, 6, 10, 12, 15];
|
||||
Console.WriteLine("\n数组 nums = " + nums.PrintList());
|
||||
// 二分查找插入点
|
||||
foreach (int target in new int[] { 2, 6, 20 }) {
|
||||
|
||||
Reference in New Issue
Block a user