/**
* @param {string} s
* @return {string}
*/
var makeGood = function (s) {
let stack = [];
for (let i = 0; i < s.length; i++) {
let nextChar = s[i];
if (stack.length === 0) {
stack.push(s[i]);
} else if (
stack[stack.length - 1]?.toLowerCase() === s[i].toLocaleLowerCase()
) {
if (
(nextChar === nextChar?.toUpperCase() &&
stack[stack.length - 1] !== stack[stack.length - 1]?.toUpperCase()) ||
(stack[stack.length - 1] == stack[stack.length - 1]?.toUpperCase() &&
nextChar !== nextChar?.toUpperCase())
) {
stack.pop();
} else {
stack.push(nextChar);
}
} else {
stack.push(nextChar);
}
}
return stack.length > 0 ? stack.join("") : "";
};
console.log(makeGood("lEeeetcode"));
console.log(makeGood("kkdsFuqUfSDKK"));
console.log(makeGood("abBAcC"));
console.log(makeGood("Pp"));
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)