aboutsummaryrefslogtreecommitdiff
path: root/super_pow.py
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2024-10-18 00:18:13 -0600
committerJack Sangdahl <[email protected]>2024-10-18 00:18:13 -0600
commit85842b8ae346ea399be8570a49a4626d5b2f8f45 (patch)
tree6722a0bf649ed583bfa5ca30b167ab0b192ddd0e /super_pow.py
parentdbd535bd9e0d0803402c944cd40e33229dd9a0c1 (diff)
downloadleetcode-85842b8ae346ea399be8570a49a4626d5b2f8f45.tar.gz
leetcode-85842b8ae346ea399be8570a49a4626d5b2f8f45.zip
372. super pow
Diffstat (limited to 'super_pow.py')
-rw-r--r--super_pow.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/super_pow.py b/super_pow.py
new file mode 100644
index 0000000..1ec4c89
--- /dev/null
+++ b/super_pow.py
@@ -0,0 +1,28 @@
+# 372. Super Pow
+from functools import reduce
+
+"""
+your task is to calculate `a^b % 1337` where 'a' is a positive integer and
+'b' is an extremely large positive integer given in the form of an array
+"""
+
+
+class Solution(object):
+ def superPow(self, a, b):
+ """
+ :type a: int
+ :type b: List[int]
+ :rtype: int
+ """
+ return (
+ 0
+ if a % 1337 == 0
+ else pow(a, reduce(lambda x, y: (x * 10 + y) % 1140, b) + 1140, 1337)
+ )
+
+
+if __name__ == "__main__":
+ obj = Solution()
+ print(obj.superPow(a=2, b=[3]))
+ print(obj.superPow(a=2, b=[1, 0]))
+ print(obj.superPow(a=1, b=[4, 3, 3, 8, 5, 2]))