File tree Expand file tree Collapse file tree 1 file changed +2
-20
lines changed
project_euler/problem_070 Expand file tree Collapse file tree 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:
6060 Return True if num1 and num2 have the same frequency of every digit, False
6161 otherwise.
6262
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-
6963 >>> has_same_digits(123456789, 987654321)
7064 True
7165
72- >>> has_same_digits(123, 12 )
66+ >>> has_same_digits(123, 23 )
7367 False
7468
7569 >>> has_same_digits(1234566, 123456)
7670 False
7771 """
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 ))
9173
9274
9375def solution (max : int = 10000000 ) -> int :
You can’t perform that action at this time.
0 commit comments