DEV Community

Karleb
Karleb

Posted on

#1544. Make The String Great

https://leetcode.com/problems/make-the-string-great/description/?envType=daily-question&envId=2024-04-05

var makeGood = function (s) {
    const stack = [];

    for (const char of s) {
        if (
            stack.length &&
            Math.abs(char.charCodeAt() - stack[stack.length - 1].charCodeAt()) === 32
            ) {
            stack.pop();
        } else {
            stack.push(char);
        }
    }

    return stack.join('');
};

Enter fullscreen mode Exit fullscreen mode

Top comments (0)