Skip to content

Commit 3324cfe

Browse files
authored
Update 479-largest-palindrome-product.js
1 parent e97508a commit 3324cfe

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

479-largest-palindrome-product.js

+22
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
/**
2+
* @param {number} n
3+
* @return {number}
4+
*/
5+
const largestPalindrome = function (n) {
6+
if (n === 1) return 9
7+
for (let i = 2, limit = 9 * 10 ** (n - 1); i < limit; i++) {
8+
let left = 10 ** n - i
9+
let right = +('' + left).split('').reverse().join('')
10+
if (i ** 2 - 4 * right < 0) continue
11+
const tmp = (i ** 2 - 4 * right) ** 0.5
12+
if (tmp === Math.floor(tmp)) {
13+
return (
14+
(BigInt(right) + 10n ** BigInt(n) * (10n ** BigInt(n) - BigInt(i))) %
15+
1337n
16+
)
17+
}
18+
}
19+
}
20+
21+
// another
22+
123
/**
224
* @param {number} n
325
* @return {number}

0 commit comments

Comments
 (0)