Python solution, beats 97%


  • 0
    I
    class Solution(object):
        def superPow(self, a, b):
            """
            :type a: int
            :type b: List[int]
            :rtype: int
            """
            mod1 = mod = a % 1337
            period = 0
            while True: # search for period
                mod = mod * mod1 % 1337
                period += 1
                if mod == mod1:
                    break
            b = int(''.join(str(i) for i in b)) # python is sweet, it has built-in bigint support
            b_adjusted = b % period
            return (mod ** b_adjusted) % 1337
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.