diff --git a/solutions/python/practice411.py b/solutions/python/practice411.py index 8d5bbc6..4ed9056 100644 --- a/solutions/python/practice411.py +++ b/solutions/python/practice411.py @@ -1,16 +1,17 @@ # Problem: Digit Frequency Score -# Source: https://leetcode.com/problems/digit-frequency-score -# Note: -# Status: IN PROGRESS +# Source: https://leetcode.com/problems/digit-frequency-score/ +# Note: Adding each digit once per occurrence is equivalent to weighting it by frequency. +# Status: ✅ Done + class Solution(object): def digitFrequencyScore(self, n): - """ - :type n: int - :rtype: int - """ - return + """Return the sum of the decimal digits of n.""" + return sum(int(digit) for digit in str(n)) + -solution = Solution() -assert solution.digitFrequencyScore(122) == 5 -assert solution.digitFrequencyScore(101) == 2 \ No newline at end of file +if __name__ == "__main__": + solution = Solution() + assert solution.digitFrequencyScore(122) == 5 + assert solution.digitFrequencyScore(101) == 2 + assert solution.digitFrequencyScore(9999) == 36