1556. Thousand Separator

Обновлено: 2024-03-12
1 мин
[]

Содержание

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])