Skip to content

Commit 45442bb

Browse files
authored
Create Decode the Message.java
1 parent 1c68634 commit 45442bb

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Easy/Decode the Message.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public String decodeMessage(String key, String message) {
3+
int counter = 0;
4+
Map<Character, Character> map = new HashMap<>();
5+
for (char c : key.toCharArray()) {
6+
if (!map.containsKey(c) && c != ' ') {
7+
map.put(c, (char) ('a' + counter++));
8+
}
9+
}
10+
StringBuilder sb = new StringBuilder();
11+
for (char c : message.toCharArray()) {
12+
sb.append(c == ' ' ? ' ' : map.get(c));
13+
}
14+
return sb.toString();
15+
}
16+
}

0 commit comments

Comments
 (0)