LeetCode 0479. Largest Palindrome Product Solution in Java, Python, C++, JavaScript, Go & Rust | Explanation + Code

CoderIndeed
0
0479. Largest Palindrome Product

Description

Given an integer n, return the largest palindromic integer that can be represented as the product of two n-digits integers. Since the answer can be very large, return it modulo 1337.

 

Example 1:

Input: n = 2
Output: 987
Explanation: 99 x 91 = 9009, 9009 % 1337 = 987

Example 2:

Input: n = 1
Output: 9

 

Constraints:

  • 1 <= n <= 8

Solutions

Solution 1

PythonJavaC++Go
class Solution: def largestPalindrome(self, n: int) -> int: mx = 10**n - 1 for a in range(mx, mx // 10, -1): b = x = a while b: x = x * 10 + b % 10 b //= 10 t = mx while t * t >= x: if x % t == 0: return x % 1337 t -= 1 return 9(code-box)

Post a Comment

0Comments

Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Check Now
Accept !