Solve problem 70 in Python.
This commit is contained in:
@@ -206,3 +206,14 @@ def get_digit_count(n):
|
||||
Returns the number of digits for n.
|
||||
"""
|
||||
return len(str(n))
|
||||
|
||||
|
||||
def is_permutation(n, p):
|
||||
""" Checks if p is a permutation of n. """
|
||||
digit_counts_n = [0 for _ in range(10)]
|
||||
digit_counts_p = [0 for _ in range(10)]
|
||||
for d_n in str(n):
|
||||
digit_counts_n[int(d_n)] += 1
|
||||
for p_n in str(p):
|
||||
digit_counts_p[int(p_n)] += 1
|
||||
return digit_counts_n == digit_counts_p
|
||||
|
||||
Reference in New Issue
Block a user