File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed
main/java/com/fishercoder/solutions
test/java/com/fishercoder Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change 1
1
package com .fishercoder .solutions ;
2
2
3
3
public class _1844 {
4
- public static class Soluiton1 {
4
+ public static class Solution1 {
5
5
public String replaceDigits (String s ) {
6
6
StringBuilder sb = new StringBuilder ();
7
7
for (char c : s .toCharArray ()) {
@@ -16,9 +16,8 @@ public String replaceDigits(String s) {
16
16
}
17
17
public static class Solution2 {
18
18
public String replaceDigits (String s ) {
19
-
20
19
char inpArr [] = s .toCharArray ();
21
- for (int i = 1 ; i < inpArr .length ; i += 2 ) {
20
+ for (int i = 1 ; i < inpArr .length ; i += 2 ) {
22
21
inpArr [i ] = (char ) (inpArr [i - 1 ] + inpArr [i ] - '0' );
23
22
}
24
23
return String .valueOf (inpArr );
Original file line number Diff line number Diff line change 5
5
import org .junit .BeforeClass ;
6
6
import org .junit .Test ;
7
7
8
-
9
8
public class _1844Test {
9
+ private static _1844 .Solution1 solution1 ;
10
10
private static _1844 .Solution2 solution2 ;
11
11
private static String s ;
12
12
private static String actual ;
13
13
14
14
@ BeforeClass
15
15
public static void setup () {
16
+ solution1 = new _1844 .Solution1 ();
16
17
solution2 = new _1844 .Solution2 ();
17
18
}
18
19
19
20
@ Test
20
21
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 () {
21
30
s = "a1c1e1" ;
22
31
actual = "abcdef" ;
23
32
String expected = solution2 .replaceDigits (s );
You can’t perform that action at this time.
0 commit comments