-
Notifications
You must be signed in to change notification settings - Fork 7
/
Program.cs
46 lines (43 loc) · 808 Bytes
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using FindTheIndexOfTheLargeInteger;
namespace FindTheIndexOfTheLargeInteger
{
class ArrayReader
{
public int CompareSub(int l, int r, int x, int y) => 0;
public int Length() => 0;
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
public int GetIndex(ArrayReader reader)
{
int li = 0, hi = reader.Length() - 1;
while (li < hi)
{
int mid = li + (hi - li) / 2;
if (mid - li + 1 == hi - mid)
{
if (reader.CompareSub(li, mid, mid + 1, hi) < 0)
li = mid + 1;
else
hi = mid;
}
else
{
int res = reader.CompareSub(li + 1, mid, mid + 1, hi);
if (res == 0)
return li;
if (res > 0)
hi = mid;
else
li = mid + 1;
}
}
return li;
}
}
}