1556. Thousand Separator

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1556

class Solution:
    def thousandSeparator(self, n: int) -> str:
        cnt = 0
        res = []
        while 1:
            n, v = divmod(n, 10)
            res.append(str(v))
            cnt += 1
            if n == 0:
                break
            if cnt == 3:
                res.append('.')
                cnt = 0
        return ''.join(res[::-1])