Digit Counter
Given a non-negative integer n, count how many times each digit appears in its written form. Return a dictionary where each key is a digit as a string, and each value is the number of times that digit appears. Include only digits that actually occur in the number.
Примеры
Ввод
112233Вывод
{"1": 2, "2": 2, "3": 2}Ввод
0Вывод
{"0": 1}Ввод
1000Вывод
{"0": 3, "1": 1}Нужно реализовать
def digit_frequency(n: int) -> dict:
Теги
hashmapstrings
Kirjaudu sisään nähdäksesi palautushistorian
Kirjaudu sisäänKirjaudu sisään käyttääksesi tekoälymentoria
Kirjaudu sisäänVisible tests
1
Input
112233Expected
{"1":2,"2":2,"3":2}2
Input
0Expected
{"0":1}3
Input
1000Expected
{"0":3,"1":1}4
Input
10Expected
{"0":1,"1":1}5
Input
112234Expected
{"1":2,"2":2,"3":1,"4":1}6
Input
-1Expected
{"1":1,"-":1}Focus radio
Paused · SomaFM · Fluid