티스토리 뷰
직접 binary search algorithm을 구현하는 경우 (출처 : https://github.com/python/cpython/blob/master/Lib/bisect.py)
def bisect(a, x, lo=0, hi=None):
if lo < 0:
raise ValueError('lo must be non-negative')
if hi is None:
hi = len(a)
while lo < hi:
mid = (lo + hi) // 2
if a[mid] < x:
lo = mid + 1
else:
hi = mid
return lo
mylist = [1, 2, 3, 7, 9, 11, 33]
print(bisect(mylist, 3))
python의 binary search module의 bisect 메소드 이용
import bisect
mylist = [1, 2, 3, 7, 9, 11, 33]
print(bisect.bisect(mylist, 3))
프로그래머스 - 파이썬을 파이썬답게 강의를 듣고 정리한 내용
programmers.co.kr/learn/courses/4008
'python' 카테고리의 다른 글
| python inf (0) | 2021.04.03 |
|---|---|
| 클래스 인스턴스 출력하기 (0) | 2021.04.03 |
| python - swap (0) | 2021.04.03 |
| flag or for-else (0) | 2021.04.03 |
| List comprehension의 if 문 (0) | 2021.04.03 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- initBinder
- ValidataionUtils
- divmod
- 선형 탐색
- 파이썬
- Django
- 이진 탐색
- python
- sequence type
- postfix notation
- python flag
- springboot
- string module
- Stack
- 출력 형식 지정
- tailwind
- djnago
- 스택
- most_common
- rjust
- 직접 주입
- 의존 주입
- airbnb clone
- 자료구조
- valid annotation
- 스프링부트
- 선형 배열
- ljust
- for-else
- 양방향 연결 리스트
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 |
글 보관함
