Skip to content

Commit 83480f2

Browse files
authored
Create thousand-separator.py
1 parent 7fae40a commit 83480f2

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Python/thousand-separator.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def thousandSeparator(self, n):
6+
"""
7+
:type n: int
8+
:rtype: str
9+
"""
10+
result = []
11+
s = str(n)
12+
for i, c in enumerate(str(n)):
13+
if i and (len(s)-i)%3 == 0:
14+
result.append(".")
15+
result.append(c)
16+
return "".join(result)

0 commit comments

Comments
 (0)