[leetcode, JS] 2325. Decode the Message

mxxn·2024년 5월 17일
0

leetcode

목록 보기
157/198

문제

문제 링크 : Decode the Message

풀이

/**
 * @param {string} key
 * @param {string} message
 * @return {string}
 */
var decodeMessage = function(key, message) {
    let result = ''
    key = [...new Set(key.split(' ').join(''))]
    const alphabet = 'abcdefghijklmnopqrstuvwxyz'
    for(let al of message) {
        result += alphabet[key.indexOf(al)] ?? ' '
    }
    return result
};
  1. key의 띄어쓰기와 중복제거를 해주고
  2. 해당 key에서 message의 문자들의 index를 찾아주고
  3. 그 index에 해당하는 alphabet 찾아서 result+
  • Runtime 54 ms, Memory 50.73 MB
profile
내일도 글쓰기

0개의 댓글