1556. Thousand Separator
Given an integer n
, add a dot (".") as the thousands separator and return it in string format.
Example 1:
Input: n = 987
Output: "987"
Example 2:
Input: n = 1234
Output: "1.234"
Constraints:
class Solution:
def thousandSeparator(self, n: int) -> str:
s = str(n)[::-1]
answer = ""
for i, v in enumerate(s):
if i % 3 == 0 and i != 0:
answer += "."
answer += v
return answer[::-1]