Solve problem 112 and add custom cache decorator

This commit is contained in:
2021-04-25 10:20:21 -04:00
parent 1883768d08
commit 26b11ed519
2 changed files with 49 additions and 0 deletions

View File

@@ -218,3 +218,15 @@ def is_permutation(n, p):
for p_n in str(p):
digit_counts_p[int(p_n)] += 1
return digit_counts_n == digit_counts_p
def cache(f):
cache = {}
def func_cached(*args):
if args in cache:
return cache[args]
r = f(*args)
cache[args] = r
return r
return func_cached