当前位置:网站首页>Guess the size of the number
Guess the size of the number
2022-06-25 06:13:00 【々 orange if ℃ №】
Learning goals :
A daily topic - Guess the size of the numbers
Learning content :
The rules of the number guessing game are as follows :
Every round of the game , I'll start from 1 To n Randomly choose a number . Please guess which number is chosen .
If you guessed wrong , I'll tell you , Is your guess larger or smaller than the number I selected .
You can call a predefined interface int guess(int num) To get a guess , The total number of return values is 3 A possible situation (-1,1 or 0):
-1: The number I picked is smaller than your guess pick < num
1: The number I picked was bigger than you guessed pick > num
0: I picked the same number as you guessed . Congratulations ! You guessed it !pick == num
Back to the number I picked .

solution :
# 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: int) -> int:
class Solution:
def guessNumber(self, n: int) -> int:
left, right = 1, n
while left < right:
mid = (left + right) // 2
if guess(mid) <= 0:
right = mid # The answer is in the interval [left, mid] in
else:
left = mid + 1 # The answer is in the interval [mid+1, right] in
# At this time there is left == right, The interval is reduced to a point , Is the answer
return left

边栏推荐
- The e-book "action guide for large organizations to further promote zero code application platform" was officially released!
- 3-7sql injection website instance step 3: attack type and attack strategy
- The locally developed SAP ui5 application is deployed to the ABAP server to perform error analysis
- Research Report on investment share and application prospect of 1,3-propanediol (PDO) industry in the world and China 2022
- Vscode voice notes to enrich information (Part 1)
- Summary of 6 common methods of visual deep learning model architecture
- SAP ui5 date type sap ui. model. type. Analysis of date parsing format
- A + B Again
- DOM proficient? What is the difference between node and elment?
- SAP ui5 application development tutorial XXIX - Introduction to routing and navigation functions of SAP ui5 trial version
猜你喜欢

Socket, network model notes
Part 33 of SAP ui5 application development tutorial - trial version of responsiveness of SAP ui5 applications

Soft exam information system project manager_ Information system security management - Senior Information System Project Manager of soft test 026
Yunda's cloud based business in Taiwan construction 𞓜 practical school

【LeetCode】40. Combined summation II (2 strokes of wrong questions)
Vscode voice notes to enrich information (medium)
SAP ui5 date type sap ui. model. type. Analysis of date parsing format
Introduction to the main features of kyma when the cloud native application runs
SAP Fiori tools and corresponding cli (command line interface)

RT thread i/o device model and layering
随机推荐
Leetcode sword finger offer question brushing - day 27
Noi Mathematics: Dirichlet convolution
SAP ui5 Application Development Tutorial Part 30 - parameter transfer in the routing process of SAP ui5
SAP Fiori tools and corresponding cli (command line interface)
HashSet implementation class
MySQL transaction learning notes (I) first encounter
Leetcode topic [array] -36- effective Sudoku
ctfshow-misc
Add the author watermark plugin v1.4 update to the posts of elegant grass discuz plugin - some forums post errors and bugs have been fixed
Curl command – file transfer tool
Various errors and solutions encountered when deploying SAP ui5 application to ABAP server with SAP Fiori tools
How SAP ui5 device type detection device API works
Wireless industrial Internet of things data monitoring terminal
Vscode voice notes to enrich information (Part 1)
Is the securities account of Qiantang education safe? Is it reliable?
DOM proficient? What is the difference between node and elment?
Go uses channel to control concurrency
Analysis report on global and Chinese pharmaceutical excipients industry competition and marketing model 2022-2028
Wind farm visualization: wind farm data
Day19 (variable parameter, enhanced for loop traversal, generic wildcard <? >, TreeSet, linkedhashset, nested traversal of sets, set set, static import,)