-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecode_the_Message_2325.java
More file actions
36 lines (31 loc) · 913 Bytes
/
Copy pathDecode_the_Message_2325.java
File metadata and controls
36 lines (31 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package leetcode;
import java.util.HashMap;
import java.util.Map;
class Solution2325 {
public String decodeMessage(String key, String message) {
StringBuffer sb = new StringBuffer();
key = key.replace(" ", "");
Map<Character, Character> mapper = new HashMap<>();
char original = 'a';
for (int i = 0; i < key.length(); i++) {
if (!mapper.containsKey(key.charAt(i))) {
mapper.put(key.charAt(i), original++);
}
}
for (int i = 0; i < message.length(); i++) {
if (message.charAt(i) == ' ') {
sb.append(" ");
} else
sb.append(mapper.get(message.charAt(i)));
}
return sb.toString();
}
}
public class Decode_the_Message_2325 {
public static void main(String[] args) {
String key = "eljuxhpwnyrdgtqkviszcfmabo";
String message = "zwx hnfx lqantp mnoeius ycgk vcnjrdb";
Solution2325 ns = new Solution2325();
System.out.println(ns.decodeMessage(key, message));
}
}