๐ฅ Algorithm/Baekjoon
[๋ฐฑ์ค 10610๋ฒ] 30 - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs)
Lennon
2022. 4. 5. 03:13
728x90
๋ฐ์ํ
https://www.acmicpc.net/problem/10610
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
let input;
rl.on('line', function (line) {
input = line.split('').map(Number);
rl.close();
}).on('close', function () {
console.log(solution(input));
});
function solution(num) {
if (!num.includes(0)) {
return -1;
}
if (num.reduce((acc, cur) => acc + cur, 0) % 3 !== 0) {
return -1;
}
num = num.sort((a, b) => b - a);
return num.join('');
}
30์ ๋ฐฐ์๊ฐ ๋๋ ์กฐ๊ฑด์ ๋ ๊ฐ์ง์ด๋ค.
0์ด ์์ด์ผ ํ๊ณ , ๊ฐ ์๋ฆฟ์๋ฅผ ๋ํ ๊ฐ์ด 3์ด๋ ๋๋์ด ๋จ์ด์ ธ์ผ ํ๋ค.
์ด ๋ ๊ฐ๋ง ์ฒ๋ฆฌํด์ฃผ๋ฉด ์ฝ๊ฒ ๋ต์ ๊ตฌํ ์ ์๋ค. ๋ํ 10^5์๋ฆฌ ์๊น์ง ์ฃผ์ด์ง๊ธฐ ๋๋ฌธ์ ๋ฌธ์์ด๋ก ์ฒ๋ฆฌํด์ผ ์ถ๋ ฅ ์ด๊ณผ๋ฅผ ํผํ ์ ์๋ค.
728x90
๋ฐ์ํ