Created
February 9, 2023 07:34
-
-
Save PreciousNyasulu/fa6e9dafb2386e4aa0654a8cff79df4a to your computer and use it in GitHub Desktop.
Problem #0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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