We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7b99a0e commit 2e54ff8Copy full SHA for 2e54ff8
scripts/algorithms/T/Thousand Separator/Thousand Separator.java
@@ -1,17 +1,16 @@
1
+// Runtime: 0 ms (Top 100.0%) | Memory: 39.69 MB (Top 67.9%)
2
+
3
class Solution {
4
public String thousandSeparator(int n) {
- if(n==0) return "0";
- StringBuilder str = new StringBuilder();
5
- int count=0;
6
- while(n>0){
7
- int lastDigit = n%10;
8
- if(count%3==0 && count!=0){
9
- str.append(".");
10
- }
11
- str.append(lastDigit);
12
- count++;
13
- n = n/10;
14
15
- return str.reverse().toString();
+ StringBuffer str = new StringBuffer(Integer.toString(n));
+ int index = str.length() - 3;
+ while(index >= 1){
+ str.insert(index , '.');
+ index = index - 3;
+ }
+ return str.toString();
16
}
17
0 commit comments