374. Guess Number Higher or Lower
https://leetcode.com/problems/guess-number-higher-or-lower/
Python
class Solution:
def guessNumber(self, n: int) -> int:
left, right = 0, n
while left <= right:
pivot = (left+right) >> 1
result = guess(pivot)
if result == 0:
return pivot
if result == 1:
left = pivot+1
else:
right = pivot-1
return -1