题解 | #数组分组#
数组分组
https://www.nowcoder.com/practice/9af744a3517440508dbeb297020aca86
const rl = require("readline").createInterface({ input: process.stdin }); var iter = rl[Symbol.asyncIterator](); const readline = async () => (await iter.next()).value; void (async function () { // Write your code here const combine = (fiveSum, threeSum, others) => { if (others.length === 0) { if (fiveSum === threeSum) return true; else return false; } if (combine(fiveSum + others[0], threeSum, others.slice(1))) return true; if (combine(fiveSum, threeSum + others[0], others.slice(1))) return true; }; let index = 0; let arr; while ((line = await readline())) { if (index === 0) index++; else arr = line.split(" ").map(Number); } let others = []; let fiveSum = 0; let threeSum = 0; for (let a of arr) { if (a % 5 === 0) fiveSum += a; else if (a % 3 === 0) threeSum += a; else others.push(a); } if (combine(fiveSum, threeSum, others)) console.log("true"); else console.log("false"); })();