Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- 문제풀이
- db
- MySQL
- greedy
- 알고리즘
- BFS
- math
- 시뮬레이션
- 건강
- 코테
- 투포인터
- dfs
- COS PRO
- 프로그래머스
- 백준
- 문제해결
- Java
- 러닝일지
- 이분탐색
- DP
- SWEA
- binary search
- 문자열
- SQL
- priorityqueue
- 코딩테스트
- 운동기록
- BOJ
- oracle
- 자바
Archives
- Today
- Total
슈콩
[프로그래머스] Lv.2 호텔 대실 본문


[문제]
https://school.programmers.co.kr/learn/courses/30/lessons/155651#qna
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
[소스 코드]
import java.util.*;
class Solution {
public int solution(String[][] book_time) {
int answer = 0;
Arrays.sort(book_time, (a, b) -> a[0].compareTo(b[0]));
PriorityQueue<Integer> pq = new PriorityQueue<>();
for (int i = 0; i < book_time.length; i++) {
String[] startSplit = book_time[i][0].split(":");
int sTime = Integer.parseInt(startSplit[0]) * 60 + Integer.parseInt(startSplit[1]);
String[] endSplit = book_time[i][1].split(":");
int eTime = Integer.parseInt(endSplit[0]) * 60 + Integer.parseInt(endSplit[1]) + 10;
while (!pq.isEmpty() && pq.peek() <= sTime) {
pq.poll();
}
pq.offer(eTime);
answer = Math.max(answer, pq.size());
}
return answer;
}
}'Algorithms > Programmers' 카테고리의 다른 글
| [프로그래머스] 자릿수 더하기 (0) | 2025.10.23 |
|---|---|
| [프로그래머스] 자연수 뒤집어 배열로 만들기 (0) | 2025.10.23 |
| [프로그래머스] Lv.2 시소 짝꿍 (0) | 2025.10.22 |
| [프로그래머스] Lv.2 마법의 엘리베이터 (0) | 2025.10.20 |
| [프로그래머스] Lv.2 연속된 부분 수열의 합 (0) | 2025.10.18 |