๐ง codingtest/javascript 100์
๋ฌธ์ 97. ํ๋ฐฐ ๋ฐฐ๋ฌ
awesomeyelim
2022. 5. 2. 18:05
728x90
- 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(๋ฐฐ๋ฌ์, ๋ฐฐ๋ฌ์๊ฐ));