[leetcode, JS] 1544. Make The String Great

mxxn·2023년 10월 25일
0

leetcode

목록 보기
103/198

문제

문제 링크 : Make The String Great

풀이

/**
 * @param {string} s
 * @return {string}
 */
var makeGood = function(s) {
    let stack = [];
    for (character of s){
        if (stack.length != 0 && Math.abs(stack[stack.length-1].codePointAt() - character.codePointAt()) == 32){
            stack.pop();
            continue;
        }
        stack.push(character);
    }
    return stack.join("");
};
  1. stack을 만들어 s의 문자들을 비교하는 방식
  • Runtime 59 ms, Memory 44 MB
profile
내일도 글쓰기

0개의 댓글