From b001739b5099789e039cb8887146bc59cd168227 Mon Sep 17 00:00:00 2001 From: bowenyin Date: Tue, 17 Nov 2026 12:16:00 +0800 Subject: [PATCH] Implement the digit frequency score --- solutions/python/practice411.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) 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