September 8Easy
Count commas in range
- Math
Problem
You are given an integer n. Return the total number of commas used when writing all integers from [1, n] (inclusive) in standard number formatting.
In standard formatting:
A comma is inserted after every three digits from the right. Numbers with fewer than 4 digits contain no commas.
Solution
class Solution:
def countCommas(self, n: int) -> int:
return max(0, n - 999)