|
| 1 | +<h2><a href="https://leetcode.com/problems/search-insert-position/">35. Search Insert Position</a></h2><h3>Easy</h3><hr><div><p>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.</p> |
| 2 | + |
| 3 | +<p>You must write an algorithm with <code>O(log n)</code> runtime complexity.</p> |
| 4 | + |
| 5 | +<p> </p> |
| 6 | +<p><strong class="example">Example 1:</strong></p> |
| 7 | + |
| 8 | +<pre><strong>Input:</strong> nums = [1,3,5,6], target = 5 |
| 9 | +<strong>Output:</strong> 2 |
| 10 | +</pre> |
| 11 | + |
| 12 | +<p><strong class="example">Example 2:</strong></p> |
| 13 | + |
| 14 | +<pre><strong>Input:</strong> nums = [1,3,5,6], target = 2 |
| 15 | +<strong>Output:</strong> 1 |
| 16 | +</pre> |
| 17 | + |
| 18 | +<p><strong class="example">Example 3:</strong></p> |
| 19 | + |
| 20 | +<pre><strong>Input:</strong> nums = [1,3,5,6], target = 7 |
| 21 | +<strong>Output:</strong> 4 |
| 22 | +</pre> |
| 23 | + |
| 24 | +<p> </p> |
| 25 | +<p><strong>Constraints:</strong></p> |
| 26 | + |
| 27 | +<ul> |
| 28 | + <li><code>1 <= nums.length <= 10<sup>4</sup></code></li> |
| 29 | + <li><code>-10<sup>4</sup> <= nums[i] <= 10<sup>4</sup></code></li> |
| 30 | + <li><code>nums</code> contains <strong>distinct</strong> values sorted in <strong>ascending</strong> order.</li> |
| 31 | + <li><code>-10<sup>4</sup> <= target <= 10<sup>4</sup></code></li> |
| 32 | +</ul> |
| 33 | +</div> |
0 commit comments