Skip to content

Commit d1ecc61

Browse files
committed
374
1 parent d893433 commit d1ecc61

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'''
2+
1. 아이디어:
3+
이진탐색으로 풀이.
4+
2. 시간복잡도:
5+
o(log n)
6+
3. 알고리즘:
7+
이진탐색
8+
'''
9+
10+
# The guess API is already defined for you.
11+
# @param num, your guess
12+
# @return -1 if num is higher than the picked number
13+
# 1 if num is lower than the picked number
14+
# otherwise return 0
15+
# def guess(num: int) -> int:
16+
17+
class Solution:
18+
def guessNumber(self, n: int) -> int:
19+
current = n // 2 + 1
20+
21+
# while True:
22+
while True:
23+
# print(current)
24+
g = guess(current)
25+
26+
if g == -1:
27+
n = current
28+
current = n // 2
29+
elif g == 1:
30+
current = (n + current + 1) // 2
31+
else:
32+
return current

0 commit comments

Comments
 (0)