
😎풀이
s
를 배열로 변환
- 변환된 배열 순회
2-1. 현재 문자와 이전 문자가 대소문자만 다른 같은 알파벳인지 확인
2-2. 아니라면, 다음 문자로 이동하여 같은 검사 수행
2-3. 동일하다면, 현재 문자와 이전 문자를 배열에서 제거 후 처음부터 재순회
- 배열을 문자열로 변환하여 Greate String 반환환
function makeGood(s: string): string {
const splitted = [...s]
let idx = 1
while(idx < splitted.length) {
const prev = splitted[idx - 1]
const cur = splitted[idx]
const prevCode = prev.charCodeAt(0)
const curCode = cur.charCodeAt(0)
const codeGap = Math.abs(prevCode - curCode)
if(codeGap !== 32) {
idx++
continue
}
splitted.splice(idx - 1, 2)
idx = 1
}
return splitted.join('')
};