mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-24 18:43:59 +08: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_edge {
|
||||
/* 二分查找最左一个 target */
|
||||
public int BinarySearchLeftEdge(int[] nums, int target) {
|
||||
int BinarySearchLeftEdge(int[] nums, int target) {
|
||||
// 等价于查找 target 的插入点
|
||||
int i = binary_search_insertion.BinarySearchInsertion(nums, target);
|
||||
// 未找到 target ,返回 -1
|
||||
@@ -20,7 +20,7 @@ public class binary_search_edge {
|
||||
}
|
||||
|
||||
/* 二分查找最右一个 target */
|
||||
public int BinarySearchRightEdge(int[] nums, int target) {
|
||||
int BinarySearchRightEdge(int[] nums, int target) {
|
||||
// 转化为查找最左一个 target + 1
|
||||
int i = binary_search_insertion.BinarySearchInsertion(nums, target + 1);
|
||||
// j 指向最右一个 target ,i 指向首个大于 target 的元素
|
||||
@@ -36,7 +36,7 @@ public class binary_search_edge {
|
||||
[Test]
|
||||
public void Test() {
|
||||
// 包含重复元素的数组
|
||||
int[] nums = { 1, 3, 6, 6, 6, 6, 6, 10, 12, 15 };
|
||||
int[] nums = [1, 3, 6, 6, 6, 6, 6, 10, 12, 15];
|
||||
Console.WriteLine("\n数组 nums = " + nums.PrintList());
|
||||
|
||||
// 二分查找左边界和右边界
|
||||
|
||||
Reference in New Issue
Block a user