# 2325. Decode the Message ###### tags: `Leetcode` `Easy` Link: https://leetcode.com/problems/decode-the-message/description/ ## 思路 先建map然后建答案字串即可 要注意char array没有赋值的时候 每个位置的值都是0 因此这里我们可以用map[i]==0判断当前字母有没有map的值 也就是之前有没有出现过 ## Code ```java= class Solution { public String decodeMessage(String key, String message) { char[] map = new char[26]; char cur = 'a'; for(int i=0; i<key.length(); i++){ if(key.charAt(i)==' ') continue; if(map[key.charAt(i)-'a']==0){ map[key.charAt(i)-'a'] = cur++; } } StringBuilder sb = new StringBuilder(); for(int i=0; i<message.length(); i++){ if(message.charAt(i)==' ') sb.append(' '); else{ sb.append(map[message.charAt(i)-'a']); } } return sb.toString(); } } ```