mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-13 10:39:54 +08:00
fix(csharp): Modify method name to PascalCase, simplify new expression (#840)
* Modify method name to PascalCase(array and linked list) * Modify method name to PascalCase(backtracking) * Modify method name to PascalCase(computational complexity) * Modify method name to PascalCase(divide and conquer) * Modify method name to PascalCase(dynamic programming) * Modify method name to PascalCase(graph) * Modify method name to PascalCase(greedy) * Modify method name to PascalCase(hashing) * Modify method name to PascalCase(heap) * Modify method name to PascalCase(searching) * Modify method name to PascalCase(sorting) * Modify method name to PascalCase(stack and queue) * Modify method name to PascalCase(tree) * local check
This commit is contained in:
@@ -8,9 +8,9 @@ namespace hello_algo.chapter_searching;
|
||||
|
||||
public class binary_search_edge {
|
||||
/* 二分查找最左一个 target */
|
||||
public int binarySearchLeftEdge(int[] nums, int target) {
|
||||
public int BinarySearchLeftEdge(int[] nums, int target) {
|
||||
// 等价于查找 target 的插入点
|
||||
int i = binary_search_insertion.binarySearchInsertion(nums, target);
|
||||
int i = binary_search_insertion.BinarySearchInsertion(nums, target);
|
||||
// 未找到 target ,返回 -1
|
||||
if (i == nums.Length || nums[i] != target) {
|
||||
return -1;
|
||||
@@ -22,7 +22,7 @@ public class binary_search_edge {
|
||||
/* 二分查找最右一个 target */
|
||||
public int binarySearchRightEdge(int[] nums, int target) {
|
||||
// 转化为查找最左一个 target + 1
|
||||
int i = binary_search_insertion.binarySearchInsertion(nums, target + 1);
|
||||
int i = binary_search_insertion.BinarySearchInsertion(nums, target + 1);
|
||||
// j 指向最右一个 target ,i 指向首个大于 target 的元素
|
||||
int j = i - 1;
|
||||
// 未找到 target ,返回 -1
|
||||
@@ -41,7 +41,7 @@ public class binary_search_edge {
|
||||
|
||||
// 二分查找左边界和右边界
|
||||
foreach (int target in new int[] { 6, 7 }) {
|
||||
int index = binarySearchLeftEdge(nums, target);
|
||||
int index = BinarySearchLeftEdge(nums, target);
|
||||
Console.WriteLine("最左一个元素 " + target + " 的索引为 " + index);
|
||||
index = binarySearchRightEdge(nums, target);
|
||||
Console.WriteLine("最右一个元素 " + target + " 的索引为 " + index);
|
||||
|
||||
Reference in New Issue
Block a user