일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- iterator
- LeetCode
- Protocol
- concurrency
- Python Implementation
- Class
- 운영체제
- t1
- attribute
- Substring with Concatenation of All Words
- Decorator
- 109. Convert Sorted List to Binary Search Tree
- Convert Sorted List to Binary Search Tree
- 715. Range Module
- 315. Count of Smaller Numbers After Self
- shiba
- 43. Multiply Strings
- 컴퓨터의 구조
- kaggle
- Generator
- 밴픽
- 프로그래머스
- Python Code
- 파이썬
- DWG
- 30. Substring with Concatenation of All Words
- Python
- 시바견
- Regular Expression
- data science
Archives
- Today
- Total
Scribbling
[Programmers] 입국심사 본문
https://school.programmers.co.kr/learn/courses/30/lessons/43238
1. Python
def solution(n, times):
ret = max(times) * n
left, right = 0, ret
while left <= right:
mid = (left + right) // 2
cnt = 0
for time in times:
cnt += int(mid // time)
if cnt < n:
left = mid + 1
else:
ret = min(ret, mid)
right = mid - 1
return ret
2. C++
long long solution(int n, vector<int> times) {
long long ret = (long long) *max_element(times.begin(), times.end()) * n;
long long left = 0, right = ret;
while (left <= right) {
long long mid = (left + right) / 2;
long long cnt = 0;
for (long long time : times) {
cnt += mid / time;
}
if (cnt < n) {
left = mid + 1;
} else {
ret = min(ret, mid);
right = mid - 1;
}
}
return ret;
}
'Computer Science > Algorithms & Data Structures' 카테고리의 다른 글
[Programmers] 순위 (0) | 2024.06.28 |
---|---|
[Programmers] 가장 먼 노드 (0) | 2024.06.28 |
[Programmers] 징검다리 (0) | 2024.06.27 |
[Programmers] 여행경로 (0) | 2024.06.24 |
[Programmers] 아이템 줍기 (0) | 2024.06.21 |