Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7d888f5

Browse files
committed
[20230503] Solve easy problem
1 parent a1d2939 commit 7d888f5

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# https://leetcode.com/problems/first-bad-version/description/
2+
# 278. First Bad Version
3+
4+
5+
# The isBadVersion API is already defined for you.
6+
# def isBadVersion(version: int) -> bool:
7+
8+
class Solution:
9+
def firstBadVersion(self, n: int) -> int:
10+
11+
start, end = 1, n
12+
result = float("inf")
13+
14+
while start <= end:
15+
mid = (start + end) // 2
16+
if not isBadVersion(mid):
17+
start = mid + 1
18+
else:
19+
result = min(result, mid)
20+
end = mid - 1
21+
return result
22+
23+
24+
def isBadVersion(version) -> bool:
25+
# 이미 Leetcode가 구현해서 구현할 필요가 없음
26+
# 런타임 에러 때문에 만들어둠
27+
pass

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /