当前位置:网站首页>2022.07.03 (LC 6108 decryption message)

2022.07.03 (LC 6108 decryption message)

2022-07-05 00:14:00 Leeli9316

Method : simulation

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://yzsam.com/2022/186/202207050008151878.html