Simple python solution by find the loop


  • 2
    C
    class Solution(object):
        def superPow(self, a, b):
            """
            :type a: int
            :type b: List[int]
            :rtype: int
            """
            s = 1
            idx = 0
            d = {1:0}
            res = [1]
            while True:
                idx += 1
                s = (s * a) % 1337
                if s in d:
                    break
                res.append(s)
                d[s] = idx
            ib = int(''.join(map(str, b)))
            idx1 = (ib - d[s]) % (idx - d[s])
            return res[d[s]+idx1]
    

  • 0
    B

    thanks your share,but I couldn't understand your code,could you explain it?


Log in to reply
 

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