From e13023ae0d615951d76a61f1faee3d14fd3f836a Mon Sep 17 00:00:00 2001 From: ashmichheda Date: Wed, 2 Nov 2022 17:36:07 -0700 Subject: [PATCH] add fix --- .../java/com/fishercoder/solutions/_1844.java | 10 +++++++ src/test/java/com/fishercoder/_1844Test.java | 26 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/test/java/com/fishercoder/_1844Test.java diff --git a/src/main/java/com/fishercoder/solutions/_1844.java b/src/main/java/com/fishercoder/solutions/_1844.java index 812eb9709e..cb43b85216 100644 --- a/src/main/java/com/fishercoder/solutions/_1844.java +++ b/src/main/java/com/fishercoder/solutions/_1844.java @@ -14,4 +14,14 @@ public String replaceDigits(String s) { return sb.toString(); } } + public static class Solution2 { + public String replaceDigits(String s) { + + char inpArr[] = s.toCharArray(); + for(int i = 1; i < inpArr.length; i+= 2) { + inpArr[i] = (char) (inpArr[i - 1] + inpArr[i] - '0'); + } + return String.valueOf(inpArr); + } + } } diff --git a/src/test/java/com/fishercoder/_1844Test.java b/src/test/java/com/fishercoder/_1844Test.java new file mode 100644 index 0000000000..673cbb232a --- /dev/null +++ b/src/test/java/com/fishercoder/_1844Test.java @@ -0,0 +1,26 @@ +package com.fishercoder; + +import com.fishercoder.solutions._1844; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + + +public class _1844Test { + private static _1844.Solution2 solution2; + private static String s; + private static String actual; + + @BeforeClass + public static void setup() { + solution2 = new _1844.Solution2(); + } + + @Test + public void test1() { + s = "a1c1e1"; + actual = "abcdef"; + String expected = solution2.replaceDigits(s); + Assert.assertEquals(actual, expected); + } +} \ No newline at end of file