1556. 千位分隔数 LeetCode第 33 场双周赛

1556. 千位分隔数 LeetCode第 33 场双周赛

传送门

传送门

结题思路

# 思路1:
# 利用一个for循环,从len-3开始,每隔3位插入一个点。
# 总结:
# insert()函数是插入到i的前面。字符串不能修改,list才能修改。列表转字符串得使用''.join()函数。
class Solution(object):
    def thousandSeparator(self, n):
        """
        :type n: int
        :rtype: str
        """
        n = list(str(n))
        len1 = len(n)
        i = len1 - 3
        while i >= 1:
            n.insert(i, '.')
            i -= 3
        n = ''.join(n)
        return n

猜你喜欢

转载自blog.csdn.net/qq_40092110/article/details/108254514