๋ณธ๋ฌธ์œผ๋กœ ๊ฑด๋„ˆ๋›ฐ๊ธฐ

42586. ๊ธฐ๋Šฅ ๊ฐœ๋ฐœ

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


๋ฌธ์ œ ์œ ํ˜•๋‚œ์ด๋„๊ฑธ๋ฆฐ ์‹œ๊ฐ„ํ•ด๊ฒฐ ์œ ๋ฌด(โœ…/โŒ)
์Šคํƒ/ํlv.21์‹œ๊ฐ„โœ…

์„ค๊ณ„ ๋ฐฉ๋ฒ•#

  • progressesย ๋ฐฐ์—ด์„ ์ˆœํšŒํ•˜๋ฉฐย speedย ๋ฐฐ์—ด์„ ์ฐธ์กฐํ•˜์—ฌ ๊ฐ ๊ธฐ๋Šฅ๋ณ„ ๋‚จ์€ ๋‚ ์งœ ๋ฐฐ์—ด์„ ๋งŒ๋“ ๋‹ค.

  • ๋‚จ์€ ๋‚ ์งœ ๋ฐฐ์—ด์„ย reduce๋กœ ์ˆœํšŒํ•˜๋ฉฐ, ํ•จ๊ป˜ ๋ฐฐํฌ๋˜์–ด์•ผ ํ•  ๊ธฐ๋Šฅ๋“ค์€ย deploysย ( ์Šคํƒ)์— ์Œ“๋Š”๋‹ค.

  • deploysย ์˜ ๊ธธ์ด๋ฅผย answerย ์— ๋‹ด์•„๊ฐ€๋ฉฐ ๋‹ต์„ ์™„์„ฑํ•œ๋‹ค.

์ฝ”๋“œ#

function solution(progresses, speed) {    const answer = [];
    const deploys = progresses        .map((progress, i) => Math.ceil((100 - progress) / speed[i]))        .reduce((deploys, feature) => {            if (deploys.length === 0) {                deploys.push(feature);            } else if (deploys[0] >= feature) {                deploys.push(feature);            } else {                answer.push(deploys.length);                deploys = [feature];            }            return deploys;        }, []);
    answer.push(deploys.length);
    return answer;}

์‹œ๊ฐ„ ๋ณต์žก๋„#

O(n)

์–ด๋ ค์› ๋˜ ์ #

  • ์ฒ˜์Œ์— ํ๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๊ณ  ํ–ˆ๋‹ค๊ฐ€ ๊ผฌ์˜€์—ˆ๋‹ค.

  • ๋งˆ์ง€๋ง‰์— ๋‚จ์€ย deploysย ๋ฅผ ๋‹ต์— ์ถ”๊ฐ€ํ•ด์•ผ ๋œ๋‹ค๋Š”๊ฑธ ๊นœ๋นกํ–ˆ๋‹ค.

์ฐธ๊ณ ์ž๋ฃŒ#