๋ฌธ์ ๐ฝ
https://school.programmers.co.kr/learn/courses/30/lessons/42586
๋ค๋ฅธ์ฌ๋ ํ์ด ๐ฝ
function solution(progresses, speeds) {
let answer = [0];
let days = progresses.map((progress, index) => Math.ceil((100 - progress) / speeds[index]));
let maxDay = days[0];
for(let i = 0, j = 0; i< days.length; i++){
if(days[i] <= maxDay) {
answer[j] += 1;
} else {
maxDay = days[i];
answer[++j] = 1;
}
}
return answer;
}
๋ดํ์ด๐ฝ
1. ์ฑ๊ณต โญ
function solution(progresses, speeds) {
var answer = [];
while(progresses.length){
progresses.forEach((value,index)=>{
progresses[index]+=speeds[index]
})
let count=0;
while(progresses[0]>=100){
++count
progresses.shift();
speeds.shift();
}
if(count>=1){
answer.push(count)
}
}
return answer;
}
๋๋์ ๐ฝ
map ํจ์๋ ์๋ก์ด ๋ฐฐ์ด์ return ํ์ง๋ง ์๋ณธ ๋ฐฐ์ด์ ๊ฑด๋๋ฆฌ์ง ์๋๋ค..!
'๐Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
ํ๋ก๊ทธ๋๋จธ์ค ์ฝ๋ฉํ ์คํธ ํ์ด(js) > ํผ๋ก๋ (0) | 2023.07.13 |
---|---|
ํ๋ก๊ทธ๋๋จธ์ค ์ฝ๋ฉํ ์คํธ ํ์ด(js) > ํ ์ธ ํ์ฌ (0) | 2023.07.10 |
ํ๋ก๊ทธ๋๋จธ์ค ์ฝ๋ฉํ ์คํธ ํ์ด(js) > ํ ์ธ ํ์ฌ (0) | 2023.07.06 |
ํ๋ก๊ทธ๋๋จธ์ค ์ฝ๋ฉํ ์คํธ ํ์ด(js) > ํํ(lv2) (0) | 2023.07.05 |
ํ๋ก๊ทธ๋๋จธ์ค ์ฝ๋ฉํ ์คํธ ํ์ด(js) > ์์(lv2) (0) | 2023.07.04 |