Talentd
FleetCode

1556. Thousand Separator

Easy53.7% acceptance

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:

  • 0 <= n <= 231 - 1

Topics

Hints open one at a time

Hint 1
Scan from the back of the integer and use dots to connect blocks with length 3 except the last block.
25:36
Still stuck?Read 3 approaches, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def thousandSeparator(self, n: int) -> str:
3
Starter codePython 3Spaces: 4
Examples
Input
987
Input
1234
Your code is saved on this device.Solution