HTMLify
LeetCode - Count Largest Group - Python
Views: 360 | Author: abh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | class Solution: def countLargestGroup(self, n: int) -> int: groups = {} l = 0 for i in range(1, n+1): s = 0 for d in str(i): s += int(d) if s not in groups.keys(): groups[s] = [] groups[s].append(i) tl = len(groups[s]) if tl > l: l = tl c = 0 for group in groups.values(): if len(group) == l: c += 1 return c |