Skip to content

Commit

Permalink
Add 374 in c language
Browse files Browse the repository at this point in the history
  • Loading branch information
julienChemillier authored Oct 27, 2022
1 parent 98b6666 commit 042bd9d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions c/374-guess-number-higher-or-lower.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
I pick a number from 1 to n. You have to guess which number I picked.
Space: O(1)
Time: O(log(n))
*/

long guess_bis(long min, long max){
long m = (max+min)/2;
int tmp = guess(m);
if (tmp==0)
return m;
else if (tmp<0)
return guess_bis(min,m-1);
else
return guess_bis(m+1,max);
}

long guessNumber(long n){
return guess_bis(0,n);
}

0 comments on commit 042bd9d

Please sign in to comment.