1- import java .util .ArrayDeque ;
2- import java .util .ArrayList ;
3- import java .util .List ;
4- import java .util .Queue ;
1+ import java .util .*;
52
63class Solution {
4+ private static int divide (int x , int y ) {
5+ return (x % y == 0 ) ? (x / y ) : (x / y ) + 1 ;
6+ }
7+
78 public int [] solution (int [] progresses , int [] speeds ) {
89 int [] answer = {};
9- Queue <Integer > queue = new ArrayDeque <>(); // 각 일별로 며칠 내에 끝낼 수 있는지 큐에 저장
10- List <Integer > finalList = new ArrayList <>();
11-
10+ List <Integer > answerList = new ArrayList <>();
11+ Queue <Integer > queue = new ArrayDeque <>();
12+
1213 for (int i = 0 ; i < progresses .length ; i ++) {
13- int progress = progresses [i ];
14- int speed = speeds [i ];
15- int remainingTime = 0 ;
16- if ((100 - progress ) % speed == 0 ) {
17- remainingTime = (100 - progress ) / speed ;
18- } else {
19- remainingTime = ((100 - progress ) / speed ) + 1 ;
20- }
21- queue .add (remainingTime );
14+ int remainingProgresses = 100 - progresses [i ];
15+ int remainingValue = divide (remainingProgresses , speeds [i ]);
16+ queue .add (remainingValue );
2217 }
23-
24- int theBiggestRemaining = queue .isEmpty () ? 0 : queue .poll ();
25- int count = 1 ;
26- while (!queue .isEmpty ()) {
18+
19+ while (!queue .isEmpty ()) {
2720 int current = queue .poll ();
28- if (current > theBiggestRemaining ) {
29- finalList .add (count );
30- theBiggestRemaining = current ;
31- count = 1 ;
32- } else {
21+ int count = 1 ;
22+
23+ while (!queue .isEmpty () && queue .peek () <= current ) {
24+ queue .poll ();
3325 count ++;
3426 }
27+ answerList .add (count );
28+ }
29+ answer = new int [answerList .size ()];
30+ for (int i = 0 ; i < answerList .size (); i ++) {
31+ answer [i ] = answerList .get (i );
3532 }
36- finalList .add (count );
37- answer = finalList .stream ().mapToInt (i -> i ).toArray ();
33+
3834 return answer ;
3935 }
4036}
0 commit comments