-
๋ฌธ์ 97. ํ๋ฐฐ ๋ฐฐ๋ฌ๐ง codingtest/javascript 100์ 2022. 5. 2. 18:05728x90
- n ๋ช ์ ํ๋ฐฐ ๋ฐฐ๋ฌ์์ ์์ธ ํ๋ฐฐ๋ฅผ ๋ฐฐ๋ฌํด์ผ ํ๋ค.(๋ชจ๋ ํ๋ฐฐ์ ๋ฐฐ์ก์๊ฐ์ 1์ด์์ด๋ฉฐ, ์๋ณต์๊ฐ์)
- ๊ฑฐ๋ฆฌ 1๋น 1์ ์๊ฐ์ด ๊ฑธ๋ฆฐ๋ค๊ณ ๊ฐ์ ํ์์ ๋,
๋ชจ๋ ํ๋ฐฐ๊ฐ ์๋ฃ๋ ์๊ฐ์ ๊ตฌํ์์ค.
ex) ๋ฐฐ๋ฌ์์ด 3๋ช ์ด๊ณ ๊ฐ ๊ฑฐ๋ฆฌ๊ฐ [1,2,1,3,3,3]์ธ ์์๋ก ๋ค์ด์ค๋ ๊ฒฝ์ฐ
// ์ ๋ ฅ ๋ฐฐ๋ฌ์ = 3; ๋ฐฐ๋ฌ์๊ฐ = [1, 2, 1, 3, 3, 3]; // ์ถ๋ ฅ 5
๋ต
function sol(n, l) { let answer = 0; let man = new Array(n).fill(0); console.log(man); while (l.length !== 0) { for (let j = 0; j < man.length; j++) { if (man[j] == 0 && 1) { man[j] += l.shift(); console.log(man); } } man = man.map((x) => (x = x - 1)); console.log(man); answer += 1; } return answer + Math.max.apply(null, man); } const ๋ฐฐ๋ฌ์ = 3; const ๋ฐฐ๋ฌ์๊ฐ = [1, 2, 1, 3, 3, 3]; console.log(sol(๋ฐฐ๋ฌ์, ๋ฐฐ๋ฌ์๊ฐ));
'๐ง codingtest > javascript 100์ ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๋ฌธ์ 99. ๊ฐ๊ตฌ๋ฆฌ๋ค์ ํ์ง (0) 2022.05.03 ๋ฌธ์ 96. ๋์ ํ ๋ฐญ ๋ง๋ค๊ธฐ (0) 2022.04.29 ๋ฌธ์ 95. ๋์ฅ์ฐ๊ธฐ (0) 2022.04.28 ๋ฌธ์ 86. ํ์ ์ด๋ฐฅ (0) 2022.04.27 ๋ฌธ์ 85. ์ซ์๋์ด(์ซ์ ๋์ ์ํค๊ธฐ) (0) 2022.04.26