๋ฐ์ํ
[ํ๋ก๊ทธ๋๋จธ์ค] ๊ธฐ๋ฅ๊ฐ๋ฐ
https://programmers.co.kr/learn/courses/30/lessons/42586
๋ฌธ์ ์ ๊ทผ
๊ฐ ๊ธฐ๋ฅ๋ง๋ค ๋จ์ ์ผ์๋ฅผ ๊ณ์ฐํด์ฃผ๊ณ , ์ ๊ธฐ๋ฅ์ ๋จ์ ์ผ์๋ณด๋ค ์์ ์ผ์๋ฅผ ๊ฐ์ง ๊ธฐ๋ฅ๋ง๋ค count๋ฅผ ์ฆ๊ฐ์์ผ์ ํ ๋ฐฐํฌ ๋จ๊ณ์ ํฌํจ๋๋๋ก ์ ๊ทผํ๋ค.
Code
import java.util.ArrayList;
class Solution {
public int[] solution(int[] progresses, int[] speeds) {
int[] remainDays = new int[progresses.length];
//๊ฐ ๊ธฐ๋ฅ์ ์๋ฃํ๋๋ฐ ๊ฑธ๋ฆฌ๋ ์ผ ์ ์ฅ
for(int i = 0; i<progresses.length; i++){
int remain = 100 - progresses[i];
remainDays[i] = (remain % speeds[i] == 0) ? remain/speeds[i] : remain/speeds[i] + 1;
}
// ๊ฐ๊ฐ ๋ฐฐํฌ ๋จ๊ณ์์ ๋ช๊ฐ์ ๊ธฐ๋ฅ์ด ํฌํจ๋ ์ง ๊ณ์ฐ
ArrayList<Integer> deploy = new ArrayList<>();
for(int i = 0 ; i< remainDays.length; i++){
if(remainDays[i]<0) continue;
int count = 1;
for(int j = i+1; j<remainDays.length; j++){
if(remainDays[j] >remainDays[i]) break;
remainDays[j] = -1;
count++;
}
deploy.add(count);
}
int[] answer = new int[deploy.size()];
for(int i = 0; i<answer.length; i++){
answer[i] = deploy.get(i);
}
return answer;
}
}
์ด๋ ค์ ๋ ์ / ๋ฐฐ์ด ์ / ๋๋ ์
๋ฌธ์ ๋ถ๋ฅ๊ฐ ์คํ/ํ๋ก ๋ถ๋ฅ๋์ด ์์ด์ ํ๋ฅผ ์ด์ฉํด์ ํ์ด๋ณด๋ ค๊ณ ํ๋ค๊ฐ ์คํจํด์ ๊ทธ๋ฅ ์๊ฐ๋๋๋๋ก ํ์๋ค.
๋ฐ์ํ
'Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Algorithm/Java][๋ฐฑ์ค] 14502 ์ฐ๊ตฌ์ (0) | 2022.03.05 |
---|---|
[Algorithm/Java][ํ๋ก๊ทธ๋๋จธ์ค] ๋ ๋งต๊ฒ (0) | 2022.02.26 |
[Algorithm/Java][ํ๋ก๊ทธ๋๋จธ์ค] ์นด์นด์คํ๋ ์ฆ ์ปฌ๋ฌ๋ง๋ถ (0) | 2022.02.17 |
[Algorithm/Java][๋ฐฑ์ค] 1676๋ฒ ํฉํ ๋ฆฌ์ผ 0์ ๊ฐ์ (0) | 2022.02.14 |
[Algorithm/Java][ํ๋ก๊ทธ๋๋จธ์ค] ์ ๊ณ ๊ฒฐ๊ณผ ๋ฐ๊ธฐ (0) | 2022.02.14 |