mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-11 15:06:07 +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_divide_and_conquer;
|
||||
|
||||
public class binary_search_recur {
|
||||
/* 二分查找:问题 f(i, j) */
|
||||
public int DFS(int[] nums, int target, int i, int j) {
|
||||
int DFS(int[] nums, int target, int i, int j) {
|
||||
// 若区间为空,代表无目标元素,则返回 -1
|
||||
if (i > j) {
|
||||
return -1;
|
||||
@@ -28,7 +28,7 @@ public class binary_search_recur {
|
||||
}
|
||||
|
||||
/* 二分查找 */
|
||||
public int BinarySearch(int[] nums, int target) {
|
||||
int BinarySearch(int[] nums, int target) {
|
||||
int n = nums.Length;
|
||||
// 求解问题 f(0, n-1)
|
||||
return DFS(nums, target, 0, n - 1);
|
||||
@@ -37,7 +37,7 @@ public class binary_search_recur {
|
||||
[Test]
|
||||
public void Test() {
|
||||
int target = 6;
|
||||
int[] nums = { 1, 3, 6, 8, 12, 15, 23, 26, 31, 35 };
|
||||
int[] nums = [1, 3, 6, 8, 12, 15, 23, 26, 31, 35];
|
||||
|
||||
// 二分查找(双闭区间)
|
||||
int index = BinarySearch(nums, target);
|
||||
|
||||
Reference in New Issue
Block a user