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) {
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 }
Original file line number Diff line number Diff line change 66import org .junit .Test ;
77
88public 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 );
You can’t perform that action at this time.
0 commit comments