Count Largest Group LeetCode solution in Python
1def compute(num):2if num < 10:3return num45newVal = 067while num > 0:8last = num % 109newVal += last10num /= 101112return newVal131415class Solution(object):16def countLargestGroup(self, n):17"""18:type n: int19:rtype: int20"""21myMap = {}2223for i in range(1, n + 1):24val = compute(i)2526if val in myMap.keys():27myMap.get(val).append(i)28else:29myMap[val] = [i]3031maxLen = 03233for n in myMap.values():34maxLen = max(maxLen, len(n))3536ans = 03738for n in myMap.values():39if len(n) == maxLen:40ans += 14142return ans