42586. ๊ธฐ๋ฅ ๊ฐ๋ฐ
์ฝ๋ฉํ ์คํธ ์ฐ์ต - ๊ธฐ๋ฅ๊ฐ๋ฐ
| ๋ฌธ์ ์ ํ | ๋์ด๋ | ๊ฑธ๋ฆฐ ์๊ฐ | ํด๊ฒฐ ์ ๋ฌด(โ /โ) |
|---|---|---|---|
| ์คํ/ํ | lv.2 | 1์๊ฐ | โ |
์ค๊ณ ๋ฐฉ๋ฒ#
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๋ฅผ ๋ต์ ์ถ๊ฐํด์ผ ๋๋ค๋๊ฑธ ๊น๋นกํ๋ค.