当前位置:网站首页>2022.07.03(LC_6108_解密消息)

2022.07.03(LC_6108_解密消息)

2022-07-05 00:08:00 Leeli9316

方法:模拟

class Solution {
    public String decodeMessage(String key, String message) {
        Map<Character, Character> map = new HashMap<>();
        char c = 'a';
        for (char ch : key.replace(" ", "").toCharArray()) {
            if (!map.containsKey(ch)) {
                map.put(ch, c++);
            }
        }
        char[] m = message.toCharArray();
        for (int i = 0; i < m.length; i++) {
            if (m[i] != ' ') {
                m[i] = map.get(m[i]);
            }
        }
        return new String(m);
    }
}

 

原网站

版权声明
本文为[Leeli9316]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Leeli9316/article/details/125585037