8000 refactor 1844 · githubniraj/Leetcode@05cedd9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 05cedd9

Browse files
refactor 1844
1 parent 7b3ef50 commit 05cedd9

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/main/java/com/fishercoder/solutions/_1844.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.fishercoder.solutions;
22

33
public class _1844 {
4-
public static class Soluiton1 {
4+
public static class Solution1 {
55
public String replaceDigits(String s) {
66
StringBuilder sb = new StringBuilder();
77
for (char c : s.toCharArray()) {
@@ -16,9 +16,8 @@ public String replaceDigits(String s) {
1616
}
1717
public static class Solution2 {
1818
public String replaceDigits(String s) {
19-
2019
char inpArr[] = s.toCharArray();
21-
for(int i = 1; i < inpArr.length; i+= 2) {
20+
for (int i = 1; i < inpArr.length; i += 2) {
2221
inpArr[i] = (char) (inpArr[i - 1] + inpArr[i] - '0');
2322
}
2423
return String.valueOf(inpArr);

src/test/java/com/fishercoder/_1844Test.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,28 @@
55
import org.junit.BeforeClass;
66
import org.junit.Test;
77

8-
98
public class _1844Test {
9+
private static _1844.Solution1 solution1;
1010
private static _1844.Solution2 solution2;
1111
private static String s;
1212
private static String actual;
1313

1414
@BeforeClass
1515
public static void setup() {
16+
solution1 = new _1844.Solution1();
1617
solution2 = new _1844.Solution2();
1718
}
1819

1920
@Test
2021
public void test1() {
22+
s = "a1c1e1";
23+
actual = "abcdef";
24+
String expected = solution1.replaceDigits(s);
25+
Assert.assertEquals(actual, expected);
26+
}
27+
28+
@Test
29+
public void test2() {
2130
s = "a1c1e1";
2231
actual = "abcdef";
2332
String expected = solution2.replaceDigits(s);

0 commit comments

Comments
 (0)
0