修改目录结构,优化CMakeLists

This commit is contained in:
2024-09-16 08:12:23 +08:00
parent a1127e008f
commit 1e9de7c9c2
27 changed files with 6 additions and 26 deletions
+52
View File
@@ -0,0 +1,52 @@
#include <leetcode/utils.h>
#include <stdio.h>
static int pick = 0;
/**
* Forward declaration of guess API.
* @param num your guess
* @return -1 if num is higher than the picked number
* 1 if num is lower than the picked number
* otherwise return 0
* int guess(int num);
*/
int guess(int num)
{
if (num > pick)
return -1;
if (num < pick)
return 1;
return 0;
}
int guessNumber(int n)
{
int low = 1, high = n;
while (low < high)
{
int res = guess((low + high) / 2);
if (res == -1)
high = (n + 1) / 2;
else if (res == 1)
low = (low + high) / 2;
else
return res;
}
return high + guess(high);
}
int main()
{
pick = 6;
ASSERT(guessNumber(10), pick, fail);
pick = 1;
ASSERT(guessNumber(2), pick, fail);
return 0;
fail:
return -1;
}