Skip to content

Commit 94e8882

Browse files
committed
Runtime: 44 ms (Top 29.7%) | Memory: 16.32 MB (Top 23.9%)
1 parent b3745a6 commit 94e8882

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
class Solution:
2-
def thousandSeparator(self, n: int) -> str:
3-
nums = str(n)
4-
count = 0
5-
result = ""
6-
i = len(nums)-1
7-
8-
while i >= 0:
9-
result = nums[i] + result
10-
count +=1
1+
# Runtime: 44 ms (Top 29.7%) | Memory: 16.32 MB (Top 23.9%)
112

12-
if count == 3 and i != 0:
13-
count = 0
14-
result = "." + result
15-
i-=1
16-
return result
3+
class Solution:
4+
def thousandSeparator(self, n: int) -> str:
5+
s=str(n)
6+
s=s[::-1]
7+
res = '.'.join(s[i:i + 3] for i in range(0, len(s), 3))
8+
return res[::-1]

0 commit comments

Comments
 (0)