Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1775 from AP-Repositories/patch-46
Browse files Browse the repository at this point in the history
Create 0374-guess-number-higher-or-lower.cpp
  • Loading branch information
Ahmad-A0 authored Jan 1, 2023
2 parents 983ef66 + dc9be9e commit 6624640
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cpp/0374-guess-number-higher-or-lower.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution {
public:
int guessNumber(int n) {
int low = 1;
int high = n;

while(true) {
int mid = low + (high - low)/2;
int myGuess = guess(mid);
if(myGuess == 1)
low = mid + 1;
else if(myGuess == -1)
high = mid - 1;
else
return mid;
}
}
};

0 comments on commit 6624640

Please sign in to comment.