Find the largest palindrome made from the product of two n-digit numbers.
 Since the result could be very large, you should return the largest palindrome mod 1337.

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




Note:
The range of n is [1,8].

Difficulty: introductory

Starter code:

class Solution:
    def largestPalindrome(self, n: int) -> int:
        

Solutions:
class Solution:
     def largestPalindrome(self, n):
         """
         :type n: int
         :rtype: int
         """
         A = [0,9,987,123,597,677,1218,877,475]
         return A[n]

class Solution:
     def largestPalindrome(self, n):
         """
         :type n: int
         :rtype: int
         """
         return [9, 9009, 906609, 99000099, 9966006699, 999000000999, \
                     99956644665999, 9999000000009999][n - 1] % 1337

class Solution(object):
     def largestPalindrome(self, n):
         if n==1: return 9
         for a in range(2, 9*10**(n-1)):
             hi=(10**n)-a
             lo=int(str(hi)[::-1])
             if a**2-4*lo < 0: continue
             if (a**2-4*lo)**.5 == int((a**2-4*lo)**.5):
                 return (lo+10**n*(10**n-a))%1337

class Solution:
     def largestPalindrome(self, n):
         if n==1: return 9
         if n==2: return 987
         for a in range(2, 9*10**(n-1)):
             hi=(10**n)-a
             lo=int(str(hi)[::-1])
             if a**2-4*lo < 0: continue
             if (a**2-4*lo)**.5 == int((a**2-4*lo)**.5):
                 return (lo+10**n*(10**n-a))%1337

class Solution:
     def largestPalindrome(self, n):
         """
         :type n: int
         :rtype: int
         """
         if n == 1: return 9
         if n == 2: return 987
         for i in range(2, 9*10**(n-1)):
             hi = (10**n) - i
             lo = int(str(hi)[::-1])
             if i**2 - 4*lo < 0: continue
             if (i**2 - 4*lo)**0.5 == int((i**2-4*lo)**0.5):
                 return (lo+10**n*(10**n-i))%1337

class Solution:
     def largestPalindrome(self, n):
         """
         :type n: int
         :rtype: int
         """
         if n==1: return 9
         if n==2: return 987
         for a in range(2, 9*10**(n-1)):
             hi=(10**n)-a
             lo=int(str(hi)[::-1])
             if a**2-4*lo < 0: continue
             if (a**2-4*lo)**.5 == int((a**2-4*lo)**.5):
                 return (lo+10**n*(10**n-a))%1337

class Solution:
     def largestPalindrome(self, n):
         """
         :type n: int
         :rtype: int
         """
         
         table = [9, 9009, 906609, 99000099, 9966006699, 999000000999, 99956644665999, 9999000000009999]
         return table[n - 1] % 1337
     
         ''' Time Limited when n = 8 , maybe caused by the lowly run time of python
         if n == 1:
             return 9
         maxNum = int(pow(10, n)) - 1
         for i in reversed(range(maxNum // 10, maxNum)):
             palindrome = self.createPalindrome(i)
             j = maxNum
             while j * j >= palindrome:
                 if palindrome % j == 0:
                     return palindrome % 1337
                 j -= 1
         return 0
     
     def createPalindrome(self, n):
         palindrome = str(n)
         reverse = str(n)[::-1]
         palindrome += reverse
         return int(palindrome)
         '''


class Solution:
     def largestPalindrome(self, n):
         """
         :type n: int
         :rtype: int
         """
         if n == 1:
             return 9
         for a in range(2,9*10**(n-1)):
             upper = 10**n - a
             lower = int(str(upper)[::-1])
             delta = a**2 - 4*lower
             if delta >= 0 and int(delta**0.5) == delta**0.5 and (a+delta)%2 == 0:
                 return (upper*10**n+lower)%1337

class Solution:
     def largestPalindrome(self, n):
         """
         :type n: int
         :rtype: int
         """
         if n == 1:
             return 9
         if n == 2:
             return 987
         for a in range(1, 9*pow(10, n-1)):
             hi=(pow(10, n))-a
             lo=int(str(hi)[::-1])
             if pow(a, 2)-4*lo < 0: continue
             if pow((pow(a, 2)-4*lo), 0.5) == int(pow((pow(a, 2)-4*lo), 0.5)):
                 return (lo+pow(10, n)*(pow(10, n)-a))%1337


class Solution:
     def largestPalindrome(self, n):
         """
         :type n: int
         :rtype: int
         """
         top = pow(10, n) - 1
         bot = pow(10, n-1) - 1
         if n==1: return 9
         if n==2: return 987
         for a in range(2, 9*10**(n-1)):
             hi=(10**n)-a
             lo=int(str(hi)[::-1])
             if a**2-4*lo < 0: continue
             if (a**2-4*lo)**.5 == int((a**2-4*lo)**.5):
                 return (lo+10**n*(10**n-a))%1337