Skip to content

Commit 6ba5230

Browse files
refactor 2325
1 parent edf6621 commit 6ba5230

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public String decodeMessage(String key, String message) {
3131
return sb.toString();
3232
}
3333
}
34+
3435
public static class Solution2 {
3536

3637
public String decodeMessage(String key, String message) {
@@ -41,17 +42,20 @@ public String decodeMessage(String key, String message) {
4142
char keyArr[] = key.toCharArray();
4243
StringBuilder result = new StringBuilder();
4344

44-
for(int i = 0; i < keyArr.length; i++) {
45+
for (int i = 0; i < keyArr.length; i++) {
4546
if (keyArr[i] != ' ' && !bucket.containsKey(keyArr[i])) {
4647
bucket.put(keyArr[i], ch++);
4748
}
4849
}
4950

5051
// decode the message using the bucket
5152
char msgArr[] = message.toCharArray();
52-
for(int i = 0; i < msgArr.length; i++) {
53-
if(msgArr[i] == ' ') result.append(" ");
54-
else result.append(bucket.get(msgArr[i]));
53+
for (int i = 0; i < msgArr.length; i++) {
54+
if (msgArr[i] == ' ') {
55+
result.append(" ");
56+
} else {
57+
result.append(bucket.get(msgArr[i]));
58+
}
5559
}
5660
return result.toString();
5761
}

src/test/java/com/fishercoder/_2325Test.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,28 @@
66
import org.junit.Test;
77

88
public class _2325Test {
9+
private static _2325.Solution1 solution1;
910
private static _2325.Solution2 solution2;
1011
private String key;
1112
private String message;
1213

1314
@BeforeClass
1415
public static void setup() {
16+
solution1 = new _2325.Solution1();
1517
solution2 = new _2325.Solution2();
1618
}
1719

1820
@Test
1921
public void test1() {
22+
key = "the quick brown fox jumps over the lazy dog";
23+
message = "vkbs bs t suepuv";
24+
String actual = solution1.decodeMessage(key, message);
25+
String expected = "this is a secret";
26+
Assert.assertEquals(actual, expected);
27+
}
28+
29+
@Test
30+
public void test2() {
2031
key = "the quick brown fox jumps over the lazy dog";
2132
message = "vkbs bs t suepuv";
2233
String actual = solution2.decodeMessage(key, message);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy