File tree 1 file changed +2
-20
lines changed
project_euler/problem_070
1 file changed +2
-20
lines changed Original file line number Diff line number Diff line change @@ -60,34 +60,16 @@ def has_same_digits(num1: int, num2: int) -> bool:
60
60
Return True if num1 and num2 have the same frequency of every digit, False
61
61
otherwise.
62
62
63
- digits[] is a frequency table where the index represents the digit from
64
- 0-9, and the element stores the number of appearances. Increment the
65
- respective index every time you see the digit in num1, and decrement if in
66
- num2. At the end, if the numbers have the same digits, every index must
67
- contain 0.
68
-
69
63
>>> has_same_digits(123456789, 987654321)
70
64
True
71
65
72
- >>> has_same_digits(123, 12 )
66
+ >>> has_same_digits(123, 23 )
73
67
False
74
68
75
69
>>> has_same_digits(1234566, 123456)
76
70
False
77
71
"""
78
- digits = [0 ] * 10
79
-
80
- while num1 > 0 and num2 > 0 :
81
- digits [num1 % 10 ] += 1
82
- digits [num2 % 10 ] -= 1
83
- num1 //= 10
84
- num2 //= 10
85
-
86
- for digit in digits :
87
- if digit != 0 :
88
- return False
89
-
90
- return True
72
+ return sorted (str (num1 )) == sorted (str (num2 ))
91
73
92
74
93
75
def solution (max : int = 10000000 ) -> int :
You can’t perform that action at this time.
0 commit comments