We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e948ebe commit d1c8f76Copy full SHA for d1c8f76
479-largest-palindrome-product.js
@@ -1,3 +1,28 @@
1
+/**
2
+ * @param {number} n
3
+ * @return {number}
4
+ */
5
+function largestPalindrome(n) {
6
+ if(n === 1) return 9
7
+ let max = BigInt(10 ** n - 1), min = max / 10n + 1n
8
+ for(let h = max; h >= min; h--) {
9
+ let left = h, right = 0n
10
+ for(let i = h; i !== 0n; ) {
11
+ right = right * 10n + i % 10n
12
+ i = i / 10n
13
+ left *= 10n
14
+ }
15
+ let pal = left + right
16
+ for(let i = max; i >= min; i--) {
17
+ let j = pal / i
18
+ if(j > i) break
19
+ if(pal % i === 0n) return pal % 1337n
20
21
22
+}
23
+
24
+// another
25
26
/**
27
* @param {number} n
28
* @return {number}
0 commit comments