* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
1.1 KiB
1.1 KiB
id, title, challengeType, videoUrl, dashedName
id | title | challengeType | videoUrl | dashedName |
---|---|---|---|---|
5900f3701000cf542c50fe83 | 问题4:最大的回文产品 | 5 | problem-4-largest-palindrome-product |
--description--
回文数字读取两种方式相同。由两个2位数字的乘积制成的最大回文是9009 = 91×99。找到由两个n
数字的乘积制成的最大回文。
--hints--
largestPalindromeProduct(2)
应返回9009。
assert.strictEqual(largestPalindromeProduct(2), 9009);
largestPalindromeProduct(3)
应返回906609。
assert.strictEqual(largestPalindromeProduct(3), 906609);
--seed--
--seed-contents--
function largestPalindromeProduct(n) {
return true;
}
largestPalindromeProduct(3);
--solutions--
const largestPalindromeProduct = (digit)=>{
let start = 1;
let end = Number(`1e${digit}`) - 1;
let palindrome = [];
for(let i=start;i<=end;i++){
for(let j=start;j<=end;j++){
let product = i*j;
let palindromeRegex = /\b(\d)(\d?)(\d?).?\3\2\1\b/gi;
palindromeRegex.test(product) && palindrome.push(product);
}
}
return Math.max(...palindrome);
}