Python solution without using pow. Bit manipultaion


  • 0
    class Solution(object):
        def superPow(self, a, b):
            b = int(''.join(map(str, b)))
            res = 1
            a %= 1337
            cache = a
            while b > 0:
                if b & 1:
                    res = (res * cache) % 1337
                cache = (cache ** 2) % 1337
                b >>= 1
            return res
    
    

Log in to reply
 

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