LeetCode 374. Guess Number Higher or Lower Posted on 2021-06-14 Edited on 2024-11-24 In LeetCode 1234567891011121314class Solution {public: int guessNumber(int n) { int l = 1, r = n; while (l < r) { int mid = (r - l) / 2 + l; int ans = guess(mid); if (ans == -1) r = mid - 1; else if (ans == 1) l = mid + 1; else return mid; } return r; }};