File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ class Solution {
2+ public long solution (int n , int [] times ) {
3+ long answer = 0 ;
4+ long MAX_MAN = 1_000_000_000 ;
5+ long MAX_WORK_TIME = 1_000_000_000 ;
6+
7+ long left = 1 ; // 기다리는 시간 최소값
8+ long right = MAX_MAN * MAX_WORK_TIME ; // 입국 심사 최악의 기다리는 시간
9+ while (left <= right ) {
10+ long mid = (left + right ) / 2 ;
11+
12+ long sum = 0 ;
13+ for (int time : times ) {
14+ sum += mid / time ;
15+ }
16+
17+ if (sum >= n ) {
18+ answer = mid ;
19+ right = mid - 1 ;
20+ } else {
21+ left = mid + 1 ;
22+ }
23+ }
24+
25+ return answer ;
26+ }
27+ }
Original file line number Diff line number Diff line change 1+ import java .util .*;
2+
3+ class Solution {
4+ public String solution (String number , int k ) {
5+ StringBuilder sb = new StringBuilder ();
6+ Stack <Integer > stack = new Stack <>();
7+
8+ for (char charNum : number .toCharArray ()) {
9+ int num = charNum - '0' ;
10+
11+ while (!stack .isEmpty () && k > 0 && stack .peek () < num ) {
12+ stack .pop ();
13+ k --;
14+ }
15+ stack .push (num );
16+ // System.out.println(stack);
17+ }
18+
19+ while (k > 0 ) {
20+ stack .pop ();
21+ k --;
22+ }
23+
24+ for (int num : stack ) {
25+ sb .append (num );
26+ }
27+
28+ return sb .toString ();
29+ }
30+ }
Original file line number Diff line number Diff line change 1+ import java .util .*;
2+
3+ class Solution {
4+ class Job {
5+ int id ; // 작업 번호
6+ int start ; // 작업 시작 시간
7+ int length ; // 작업 소요 시간
8+
9+ public Job (int id , int start , int length ) {
10+ this .id = id ;
11+ this .start = start ;
12+ this .length = length ;
13+ }
14+ }
15+
16+ public int solution (int [][] jobs ) {
17+ int n = jobs .length ;
18+
19+ Arrays .sort (jobs , (a , b ) -> {
20+ if (a [0 ] == b [0 ]) return a [1 ] - b [1 ];
21+ return a [0 ] - b [0 ];
22+ });
23+
24+ PriorityQueue <Job > pq = new PriorityQueue <>((a , b ) -> {
25+ if (a .length != b .length ) return a .length - b .length ;
26+ if (a .start != b .start ) return a .start - b .start ;
27+ return a .id - b .id ;
28+ });
29+
30+ int time = 0 ; // 현재 시각
31+ int total = 0 ; // 총 반환 시간의 합
32+ int idx = 0 ; // 아직 넣지 않은 작업 인덱스
33+
34+ while (idx < n || !pq .isEmpty ()) {
35+ while (idx < n && jobs [idx ][0 ] <= time ) {
36+ pq .offer (new Job (idx , jobs [idx ][0 ], jobs [idx ][1 ]));
37+ idx ++; // 다음 작업으로
38+ }
39+
40+ if (!pq .isEmpty ()) {
41+ Job curr = pq .poll ();
42+ time += curr .length ; // 현재 시간 + 작업 실행 후 종료 시간
43+ total += (time - curr .start ); // 반환 시간 = 종료 시간 - 요청 시간
44+ } else {
45+ time = jobs [idx ][0 ]; // 다음 작업 시작 시간
46+ }
47+ }
48+
49+ return total / n ;
50+ }
51+ }
You can’t perform that action at this time.
0 commit comments