Day3. Start Algorithm

This commit is contained in:
Electrominch
2022-10-05 00:44:15 +03:00
parent c9916dabad
commit 062e03bdbf
32 changed files with 446 additions and 57 deletions

View File

@@ -0,0 +1,19 @@
namespace _35._Search_Insert_Position;
public class Solution
{
public int SearchInsert(int[] nums, int target)
{
int l = -1;
int r = nums.Length;
while (l != r - 1)
{
int i = (r + l) / 2;
if (nums[i] >= target)
r = i;
else
l = i;
}
return l + 1;
}
}