2025-08-03 12:01:18 +0000 UTC

Thousand Separator

Code

class Solution:
    def thousandSeparator(self, n: int) -> str:
        if n < 1000:
            return str(n)
        res = []
        count = 0
        while n > 0:
            res.append(str(n % 10))
            count += 1
            n //= 10
            if count % 3 == 0 and n > 0:
                res.append(".")
        res.reverse()
        return "".join(res)