Skip to content

Commit

Permalink
Add LeetCode #35 'Search Insert Position' [Easy].
Browse files Browse the repository at this point in the history
  • Loading branch information
eminencegrs committed Dec 23, 2024
1 parent c410517 commit a985643
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Search Insert Position (#35)

Given a sorted array of distinct integers and a target value, return the index if the target is found.
If not, return the index where it would be if it were inserted in order.

**You must write an algorithm with O(log n) runtime complexity.**

## Examples

### Example 1:

Input: nums = [1,3,5,6], target = 5
Output: 2

### Example 2:

Input: nums = [1,3,5,6], target = 2
Output: 1

### Example 3:

Input: nums = [1,3,5,6], target = 7
Output: 4

## Constraints

- `1 <= nums.length <= 10^4`
- `-10^4 <= nums[i] <= 10^4`
- `nums` contains distinct values sorted in ascending order.
- `-10^4 <= target <= 10^4`

0 comments on commit a985643

Please sign in to comment.