We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b3745a6 commit 94e8882Copy full SHA for 94e8882
scripts/algorithms/T/Thousand Separator/Thousand Separator.py
@@ -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
+# Runtime: 44 ms (Top 29.7%) | Memory: 16.32 MB (Top 23.9%)
11
12
- if count == 3 and i != 0:
13
14
- result = "." + result
15
- i-=1
16
- return result
+class Solution:
+ def thousandSeparator(self, n: int) -> str:
+ s=str(n)
+ s=s[::-1]
+ res = '.'.join(s[i:i + 3] for i in range(0, len(s), 3))
+ return res[::-1]
0 commit comments