Skip to content

Commit 2e54ff8

Browse files
committed
Runtime: 0 ms (Top 100.0%) | Memory: 39.69 MB (Top 67.9%)
1 parent 7b99a0e commit 2e54ff8

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1+
// Runtime: 0 ms (Top 100.0%) | Memory: 39.69 MB (Top 67.9%)
2+
13
class Solution {
24
public String thousandSeparator(int n) {
3-
if(n==0) return "0";
4-
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();
5+
6+
StringBuffer str = new StringBuffer(Integer.toString(n));
7+
int index = str.length() - 3;
8+
9+
while(index >= 1){
10+
str.insert(index , '.');
11+
index = index - 3;
12+
}
13+
14+
return str.toString();
1615
}
1716
}

0 commit comments

Comments
 (0)