File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed
main/java/com/fishercoder/solutions
test/java/com/fishercoder Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ public String decodeMessage(String key, String message) {
31
31
return sb .toString ();
32
32
}
33
33
}
34
+
34
35
public static class Solution2 {
35
36
36
37
public String decodeMessage (String key , String message ) {
@@ -41,17 +42,20 @@ public String decodeMessage(String key, String message) {
41
42
char keyArr [] = key .toCharArray ();
42
43
StringBuilder result = new StringBuilder ();
43
44
44
- for (int i = 0 ; i < keyArr .length ; i ++) {
45
+ for (int i = 0 ; i < keyArr .length ; i ++) {
45
46
if (keyArr [i ] != ' ' && !bucket .containsKey (keyArr [i ])) {
46
47
bucket .put (keyArr [i ], ch ++);
47
48
}
48
49
}
49
50
50
51
// decode the message using the bucket
51
52
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
+ }
55
59
}
56
60
return result .toString ();
57
61
}
Original file line number Diff line number Diff line change 6
6
import org .junit .Test ;
7
7
8
8
public class _2325Test {
9
+ private static _2325 .Solution1 solution1 ;
9
10
private static _2325 .Solution2 solution2 ;
10
11
private String key ;
11
12
private String message ;
12
13
13
14
@ BeforeClass
14
15
public static void setup () {
16
+ solution1 = new _2325 .Solution1 ();
15
17
solution2 = new _2325 .Solution2 ();
16
18
}
17
19
18
20
@ Test
19
21
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 () {
20
31
key = "the quick brown fox jumps over the lazy dog" ;
21
32
message = "vkbs bs t suepuv" ;
22
33
String actual = solution2 .decodeMessage (key , message );
You can’t perform that action at this time.
0 commit comments