Problem
- Leetcode 278: First Bad version
- Level: Easy
- Link
My Code
기본적인 이진탐색 문제다. 이진 탐색을 진행해주며 가장 먼저 발생하는 bad version을 체크해준다.
# The isBadVersion API is already defined for you.
# @param version, an integer
# @return an integer
# def isBadVersion(version):
class Solution:
def firstBadVersion(self, n):
left = 1
right = n
while left < right:
mid = (right + left) // 2
if not isBadVersion(mid):
left = mid + 1
else:
right = mid
return left
'개발공부 > algorithm' 카테고리의 다른 글
[Leetcode][python] 14. Longest Common Prefix (0) | 2021.07.04 |
---|---|
[Leetcode][python] 374. Guess Number Higher or Lower - Binary Search (0) | 2021.07.04 |
[Leetcode][python] 58: Length of Last Word (0) | 2021.06.24 |
[백준][python] 17626 - Four squares (0) | 2021.06.06 |
[백준][Python] 2670: 연속부분 최대합 - DP (0) | 2021.06.06 |