1399. Count Largest Group
On This Page
class Solution:
def countLargestGroup(self, n: int) -> int:
cnt = Counter()
res = mx = 0
for i in range(1, n + 1):
s = 0
while i:
s += i % 10
i //= 10
cnt[s] += 1
if mx < cnt[s]:
mx = cnt[s]
res = 1
elif mx == cnt[s]:
res += 1
return res