-
99클럽 코테 스터디 13일차 TIL + 입국심사(프로그래머스)Study(진행중)/항해99 2024. 8. 4. 03:44
오늘의 학습 키워드
- 알고리즘
- 이분탐색
공부한 내용 본인의 언어로 정리하기
https://school.programmers.co.kr/learn/courses/30/lessons/43238
이분 탐색을 활용하는 문제를 풀었다.
이분탐색은 문제가 이분탐색 문제인지 알아보는 것과
while 문 안에 조건을 잘 설정해줘야 풀 수 있는 것 같다.
풀이 과정은 다음과 같다.
1. 이분탐색의 범위는 0 ~ 최대값
2. 탐색의 범위를 좁혀가며 심사관이 n명 이상 사람을 평가할 수 있다면 범위를 줄여야 하므로 right = mid - 1로
아니라면 범위를 늘려야 하므로 left = mid + 1로 설정한다.
풀이는 다음과 같다.
class Solution { public long solution(int n, int[] times) { long answer = Long.MAX_VALUE; long left = 0, right = 1_000_000_000_000_000l; while (left <= right) { long mid = (left + right) / 2l; long count = 0; for (int time : times) { count += mid / time; } // System.out.println(mid); if (count >= n) { answer = Math.min(answer, mid); right = mid - 1; } else { left = mid + 1; } } return answer; } }
내일 학습할 것은 무엇인지
삼성 기출 문제를 아직 못풀고 디버깅중이다. 내일은 마무리해서 올려야겠다
반응형'Study(진행중) > 항해99' 카테고리의 다른 글
99클럽 코테 스터디 15일차 TIL / 소수 찾기(프로그래머스) (0) 2024.08.06 99클럽 코테 스터디 14일차 TIL / 운영체제 - 프로세스 (0) 2024.08.05 99클럽 코테 스터디 12일차 TIL + 뉴스 전하기(백준) (0) 2024.08.03 99클럽 코테 스터디 11일차 TIL + 가장 큰 수(프로그래머스) (0) 2024.08.02 99클럽 코테 스터디 10일차 TIL + 최대 힙(백준) (0) 2024.08.01