Skip to content

Commit 2d1706a

Browse files
committed
Add Python Solution(374)
1 parent cad2b7c commit 2d1706a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
min, max = 1, n
15+
while min < max:
16+
mid = (min + max) // 2
17+
res = guess(mid)
18+
if res == 0:
19+
return mid
20+
elif res < 0:
21+
max = mid
22+
else:
23+
min = mid + 1
24+
25+
return min

0 commit comments

Comments
 (0)