I tried to solve the Super Pow - LeetCode
- Super Pow
Medium
Your task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large positive integer given in the form of an array.
Example 1:
Input: a = 2, b = [3] Output: 8
Example 2:
Input: a = 2, b = [1,0] Output: 1024
My solution
import unittest
import logging
logging.basicConfig(level=logging.DEBUG, format="%(levelname)s %(message)s")
class Solution(object):
def superPow(self, a, b):
"""
:type a: int
:type b: List[int]
:rtype: int
"""
digit = int("".join(map(str, b)))
product = a ** digit
res = product % 1337
return res
class MyCase(unittest.TestCase):
def setUp(self):
self.solution = Solution()
def test_1(self):
a = 2
b = [1, 0]
answer = 1024
check = self.solution.superPow(a, b)
self.assertEqual(answer, check)
unittest.main()
The solution exceeded the time limit.
How could I improve my solution?