Notice
Recent Posts
Recent Comments
Link
ยซ   2024/12   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
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
Archives
Today
Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Lennon FE

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๊ธฐ๋Šฅ ๊ฐœ๋ฐœ (js) ๋ณธ๋ฌธ

๐Ÿ”ฅ Algorithm/Programmers

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๊ธฐ๋Šฅ ๊ฐœ๋ฐœ (js)

Lennon 2021. 10. 25. 19:07
728x90
๋ฐ˜์‘ํ˜•

https://programmers.co.kr/learn/courses/30/lessons/42586?language=javascript 

 

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ๊ธฐ๋Šฅ๊ฐœ๋ฐœ

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ํŒ€์—์„œ๋Š” ๊ธฐ๋Šฅ ๊ฐœ์„  ์ž‘์—…์„ ์ˆ˜ํ–‰ ์ค‘์ž…๋‹ˆ๋‹ค. ๊ฐ ๊ธฐ๋Šฅ์€ ์ง„๋„๊ฐ€ 100%์ผ ๋•Œ ์„œ๋น„์Šค์— ๋ฐ˜์˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋˜, ๊ฐ ๊ธฐ๋Šฅ์˜ ๊ฐœ๋ฐœ์†๋„๋Š” ๋ชจ๋‘ ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ์— ๋’ค์— ์žˆ๋Š” ๊ธฐ๋Šฅ์ด ์•ž์— ์žˆ๋Š”

programmers.co.kr

 

function solution(progresses, speeds) {
    
    const days = progresses.map((v,i) => Math.ceil((100 - progresses[i]) / speeds[i]))
    const answer = [];
    
    for(let i = 0; i < days.length; i++){
        const result = [days[i]];
        for(let j = i+1; j < days.length; j++){
            if(days[i] >= days[j]) result.push(days[j]);
            else break;
        }
        answer.push(result);
        i += result.length-1;
    }
    return answer.map((a) => a.length);
}

์Šคํƒ๊ณผ ํ๋ฅผ ์ด์šฉํ•ด ํ‘ธ๋Š” ๋ฌธ์ œ์˜€๋‹ค. 

 

shift๋ฅผ ์ด์šฉํ•ด ํ’€์–ด๋ดค์ง€๋งŒ ์†๋„๊ฐ€ ๋Š๋ ค ๊ทธ๋ƒฅ for๋ฌธ์œผ๋กœ ์ธ๋ฑ์Šค ๊ฐ’์„ ์กฐ์ ˆํ•˜์—ฌ ์ž‘์„ฑํ•˜์˜€๋‹ค.

728x90
๋ฐ˜์‘ํ˜•
Comments