Download Guess Number Higher or Lower.py
# The guess API is already defined for you. # @param num, your guess # @return -1 if my number is lower, 1 if my number is higher, otherwise return 0 # def guess(num): class Solution(object): def guessNumber(self, n): """ :type n: int :rtype: int """ # binary search begin, end = 1, n while begin <= end: mid = (begin + end) / 2 res = guess(mid) if res == 0: return mid elif res > 0: begin = mid + 1 else: end = mid - 1
Leetcode 374 Guess Number Higher or Lower problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.
Feedback is the most important part of any website.
If you have any query, suggestion or feedback, Please feel free to contact us.