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