Day3. Start Algorithm
This commit is contained in:
11
35. Search Insert Position/35. Search Insert Position.csproj
Normal file
11
35. Search Insert Position/35. Search Insert Position.csproj
Normal file
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<RootNamespace>_35._Search_Insert_Position</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
10
35. Search Insert Position/Program.cs
Normal file
10
35. Search Insert Position/Program.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace _35._Search_Insert_Position
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Hello, World!");
|
||||
}
|
||||
}
|
||||
}
|
||||
19
35. Search Insert Position/Solution.cs
Normal file
19
35. Search Insert Position/Solution.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user