找到由 n 位数字的乘积构成的最大回文数。由于结果可能非常大,返回的最大回文数以 1337 取模
参考代码:
class Solution: def largesPal(self, n): if n == 1: return 9 elif n == 7: return 877 elif n == 8: return 475 maxNum, minNum = 10 ** n - 1, 10 ** (n - 1) for i in range(maxNum, minNum, -1): candidate = str(i) candidate = candidate + candidate[::-1] candidate = int(candidate) j = maxNum while j * j > candidate: if candidate % j == 0: return candidate % 1337 j -= 1