Skip to content

Commit 0e1c874

Browse files
authored
Create 374.py
1 parent 470fa9f commit 0e1c874

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

101-500/374.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# The guess API is already defined for you.
2+
# @param num, your guess
3+
# @return -1 if num is higher than the picked number
4+
# 1 if num is lower than the picked number
5+
# otherwise return 0
6+
# def guess(num):
7+
8+
class Solution(object):
9+
def guessNumber(self, n):
10+
"""
11+
:type n: int
12+
:rtype: int
13+
"""
14+
left,right = 1,n
15+
while left<=right:
16+
mid = (left+right)/2
17+
gues = guess(mid)
18+
if gues == 0:
19+
return mid
20+
if gues == -1:
21+
right = mid -1
22+
if gues == 1:
23+
left = mid+1
24+
return -1

0 commit comments

Comments
 (0)