Skip to content

Commit ad1a681

Browse files
authored
Create check-if-number-has-equal-digit-count-and-digit-value.py
1 parent 5030c9f commit ad1a681

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
import collections
5+
6+
7+
# freq table
8+
class Solution(object):
9+
def digitCount(self, num):
10+
"""
11+
:type num: str
12+
:rtype: bool
13+
"""
14+
cnt = collections.Counter(num)
15+
return all(cnt[str(i)] == int(x) for i, x in enumerate(num))

0 commit comments

Comments
 (0)