Skip to content

Instantly share code, notes, and snippets.

@PreciousNyasulu
Created February 9, 2023 07:34
Show Gist options
  • Save PreciousNyasulu/fa6e9dafb2386e4aa0654a8cff79df4a to your computer and use it in GitHub Desktop.
Save PreciousNyasulu/fa6e9dafb2386e4aa0654a8cff79df4a to your computer and use it in GitHub Desktop.
Problem #0
using System;
class Program
{
static int FindTooSweetPoint(int n)
{
int remove = 1, add = n;
while (remove <= add)
{
int mid = remove + (add - remove) / 2;
if (isTooSweet(mid))
{
add = mid - 1;
}
else
{
remove = mid + 1;
}
}
return remove;
}
static bool isTooSweet(int i)
{
if (i > 5)
{
return true;
}
else
{
return false;
}
}
static void Main(string[] args)
{
int n = 10;
int x = FindTooSweetPoint(n);
Console.WriteLine(x);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment