[leetcode, JS] 1678. Goal Parser Interpretation

mxxn·2023년 11월 2일
0

leetcode

목록 보기
111/198

문제

문제 링크 : Goal Parser Interpretation

풀이

/**
 * @param {string} command
 * @return {string}
 */
var interpret = function(command) {
    return command.replaceAll('()', 'o').replaceAll('(al)', 'al')
};
  1. ()와 (al)을 변환하는 방식
  • Runtime 56ms, Memory 41.96MB (비효율적)

다른 풀이

/**
 * @param {string} command
 * @return {string}
 */
var interpret = function(command) {
    return command.split("()").join("o").split("(al)").join("al");
};
  1. replaceAll 대신 split과 join으로 푸는 방식
  • Runtime 47ms, Memory 41.39MB
profile
내일도 글쓰기

0개의 댓글