일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 프로젝트
- English
- Writing
- 개발자
- 파비최
- 잡생각
- Daily Challenge
- 링피트
- 쓰릴오브파이트
- 10분
- 미드시청
- 영어원서읽기
- 월간
- realclass
- 뭐든
- FIT XR
- 30분
- 읽기
- 화상영어
- 스탭퍼
- 영어공부
- leetcode
- 만화도
- 매일
- 리얼 클래스
- 3줄정리
- 괜찮음
- Problem Solving
- 운동
- 사이드
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.03.07 Today's Challenge 본문
https://leetcode.com/problems/minimum-time-to-complete-trips/
Minimum Time to Complete Trips - LeetCode
Can you solve this real interview question? Minimum Time to Complete Trips - You are given an array time where time[i] denotes the time taken by the ith bus to complete one trip. Each bus can make multiple trips successively; that is, the next trip can sta
leetcode.com
이분 탐색으로 풀면 됨.
class Solution:
def minimumTime(self, time: List[int], totalTrips: int) -> int:
l, r = 1, max(time) * totalTrips
def time_enough(tt):
trips = 0
for t in time:
trips += tt // t
return trips >= totalTrips
while l < r:
mid = (l + r) // 2
if time_enough(mid):
r = mid
else:
l = mid + 1
return l
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.03.09 Today's Challenge (0) | 2023.03.09 |
---|---|
2023.03.08 Today's Challenge (0) | 2023.03.08 |
2023.03.06 Today's Challenge (0) | 2023.03.06 |
2023.03.05 Today's Challenge (0) | 2023.03.05 |
2023.03.04 Today's Challenge (0) | 2023.03.04 |
Comments