Skip to content

Commit 07c2938

Browse files
add 2710
1 parent 3b90fd3 commit 07c2938

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-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+
| 2710 |[Remove Trailing Zeros From a String](https://leetcode.com/problems/remove-trailing-zeros-from-a-string/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2710.java) | | Easy |
1112
| 2696 |[Minimum String Length After Removing Substrings](https://leetcode.com/problems/minimum-string-length-after-removing-substrings/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2696.java) | | Easy |
1213
| 2670 |[Find the Distinct Difference Array](https://leetcode.com/problems/find-the-distinct-difference-array/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2670.java) | | Easy |
1314
| 2596 |[Check Knight Tour Configuration](https://leetcode.com/problems/check-knight-tour-configuration/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2596.java) | [:tv:](https://youtu.be/OBht8NT_09c) | Medium |
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _2710 {
4+
public static class Solution1 {
5+
public String removeTrailingZeros(String num) {
6+
StringBuilder sb = new StringBuilder();
7+
boolean trailing = true;
8+
for (int i = num.length() - 1; i >= 0; i--) {
9+
if (num.charAt(i) != '0' || !trailing) {
10+
sb.append(num.charAt(i));
11+
trailing = false;
12+
}
13+
}
14+
return sb.reverse().toString();
15+
}
16+
}
17+
}
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._2710;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _2710Test {
10+
private static _2710.Solution1 solution1;
11+
12+
@BeforeClass
13+
public static void setup() {
14+
solution1 = new _2710.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals("512301", solution1.removeTrailingZeros("51230100"));
20+
}
21+
22+
}

0 commit comments

Comments
 (0)