Class Solution
-
- All Implemented Interfaces:
public final class Solution3260 - Find the Largest Palindrome Divisible by K.
Hard
You are given two positive integers
nandk.An integer
xis called k-palindromic if:xis a palindrome.xis divisible byk.
Return the largest integer having
ndigits (as a string) that is k-palindromic.Note that the integer must not have leading zeros.
Example 1:
Input: n = 3, k = 5
Output: "595"
Explanation:
595 is the largest k-palindromic integer with 3 digits.
Example 2:
Input: n = 1, k = 4
Output: "8"
Explanation:
4 and 8 are the only k-palindromic integers with 1 digit.
Example 3:
Input: n = 5, k = 6
Output: "89898"
Constraints:
<code>1 <= n <= 10<sup>5</sup></code>
1 <= k <= 9
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final StringlargestPalindrome(Integer n, Integer k)-
-
Method Detail
-
largestPalindrome
final String largestPalindrome(Integer n, Integer k)
-
-
-
-