This commit is contained in:
krahets
2023-09-02 23:03:42 +08:00
parent 799698e67c
commit 503ca797b8
12 changed files with 314 additions and 91 deletions

View File

@@ -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) {

View File

@@ -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;
}