Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 45d7fc9

Browse files
add 1556
1 parent 1ab014e commit 45d7fc9

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1556|[Thousand Separator](https://leetcode.com/problems/thousand-separator/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1556.java) ||Easy|String|
1112
|1551|[Minimum Operations to Make Array Equal](https://leetcode.com/problems/minimum-operations-to-make-array-equal/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1551.java) | [:tv:](https://youtu.be/A-i2sxmBqAA)|Medium|Math|
1213
|1550|[Three Consecutive Odds](https://leetcode.com/problems/three-consecutive-odds/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1550.java) | |Easy|Array|
1314
|1545|[Find Kth Bit in Nth Binary String](https://leetcode.com/problems/find-kth-bit-in-nth-binary-string/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1545.java) | |Medium|String|
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _1556 {
4+
public static class Solution1 {
5+
public String thousandSeparator(int n) {
6+
String str = Integer.toString(n);
7+
StringBuilder sb = new StringBuilder();
8+
for (int i = str.length() - 1, j = 1; i >= 0; i--, j++) {
9+
sb.append(str.charAt(i));
10+
j++;
11+
if (j % 3 == 0) {
12+
sb.append(".");
13+
}
14+
}
15+
String result = sb.reverse().toString();
16+
if (result.charAt(0) == '.') {
17+
result = result.substring(1);
18+
}
19+
return result;
20+
}
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1556;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static junit.framework.TestCase.assertEquals;
8+
9+
public class _1556Test {
10+
private static _1556.Solution1 solution1;
11+
12+
@BeforeClass
13+
public static void setup() {
14+
solution1 = new _1556.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals("987", solution1.thousandSeparator(987));
20+
}
21+
22+
}

0 commit comments

Comments
 (0)