Skip to content

Commit 1b2db46

Browse files
committed
Time: 91 ms (14.45%), Space: 17.9 MB (26.37%) - LeetHub
1 parent 47417e6 commit 1b2db46

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# time complexity: O(n^2)
2+
# space compelxity: O(n)
3+
class Solution:
4+
def hasSameDigits(self, s: str) -> bool:
5+
6+
while len(s) > 2:
7+
currS = ""
8+
for i in range(1, len(s)):
9+
currS += str((int(s[i]) + int(s[i - 1])) % 10)
10+
s = currS
11+
12+
return s[0] == s[1]
13+
14+
15+
s = "3902"
16+
print(Solution().hasSameDigits(s))
17+
s = "34789"
18+
print(Solution().hasSameDigits(s))

0 commit comments

Comments
 (0)