mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-31 14:23:30 +08:00
Polish some cotents.
This commit is contained in:
@ -25,7 +25,7 @@ func binarySearch(nums: [Int], target: Int) -> Int {
|
||||
}
|
||||
|
||||
/* 二分查找(左闭右开) */
|
||||
func binarySearch1(nums: [Int], target: Int) -> Int {
|
||||
func binarySearchLCRO(nums: [Int], target: Int) -> Int {
|
||||
// 初始化左闭右开 [0, n) ,即 i, j 分别指向数组首元素、尾元素+1
|
||||
var i = 0
|
||||
var j = nums.count
|
||||
@ -56,7 +56,7 @@ enum BinarySearch {
|
||||
print("目标元素 6 的索引 = \(index)")
|
||||
|
||||
/* 二分查找(左闭右开) */
|
||||
index = binarySearch1(nums: nums, target: target)
|
||||
index = binarySearchLCRO(nums: nums, target: target)
|
||||
print("目标元素 6 的索引 = \(index)")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user