mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-24 10:33:34 +08:00
build
This commit is contained in:
@@ -141,7 +141,10 @@ status: new
|
||||
|
||||
```typescript title="binary_search_insertion.ts"
|
||||
/* 二分查找插入点(无重复元素) */
|
||||
function binarySearchInsertionSimple(nums: Array<number>, target: number): number {
|
||||
function binarySearchInsertionSimple(
|
||||
nums: Array<number>,
|
||||
target: number
|
||||
): number {
|
||||
let i = 0,
|
||||
j = nums.length - 1; // 初始化双闭区间 [0, n-1]
|
||||
while (i <= j) {
|
||||
|
||||
@@ -330,7 +330,7 @@ comments: true
|
||||
// 单层循环,时间复杂度 O(n)
|
||||
for (let i = 0; i < nums.length; i++) {
|
||||
if (m[target - nums[i]] !== undefined) {
|
||||
return [m[target-nums[i]], i];
|
||||
return [m[target - nums[i]], i];
|
||||
} else {
|
||||
m[nums[i]] = i;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user