Skip to content

Commit

Permalink
Merge pull request youngyangyang04#1435 from xiaofei-2020/exArr09
Browse files Browse the repository at this point in the history
添加(0035.搜索插入位置.md):增加typescript版本
  • Loading branch information
youngyangyang04 authored Jul 8, 2022
2 parents fc165da + cccb497 commit cc10422
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions problems/0035.搜索插入位置.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,28 @@ var searchInsert = function (nums, target) {
};
```

### TypeScript

```typescript
// 第一种二分法
function searchInsert(nums: number[], target: number): number {
const length: number = nums.length;
let left: number = 0,
right: number = length - 1;
while (left <= right) {
const mid: number = Math.floor((left + right) / 2);
if (nums[mid] < target) {
left = mid + 1;
} else if (nums[mid] === target) {
return mid;
} else {
right = mid - 1;
}
}
return right + 1;
};
```

### Swift

```swift
Expand Down

0 comments on commit cc10422

Please sign in to comment.