[leetcode, JS] 1309. Decrypt String from Alphabet to Integer Mapping

mxxn·2023년 10월 11일
0

leetcode

목록 보기
92/198

문제

문제 링크 : Decrypt String from Alphabet to Integer Mapping

풀이

/**
 * @param {string} s
 * @return {string}
 */
var freqAlphabets = function(s) {
   let decrypted = '';
   for(let i=0; i < s.length; i++){
       if(s[i+2] === '#'){
           decrypted += decrypt(s[i++] + s[i++]);
       }else{
           decrypted += decrypt(s[i]);
       }
   } 
   return decrypted;
};

const decrypt = (str) => String.fromCharCode(parseInt(str) + 96);
  1. s[i+2]가 '#'인지 아닌지로 분기하여 알파벳 찾아내는 풀이
  • Runtime 44 ms, Memory 41.5 MB
profile
내일도 글쓰기

0개의 댓글