
😎풀이
words 순회
1-1. 각 문자의 사전 순 간격 기록
1-2. 간격 배열을 문자열 형태로 형 변환 하여 key를 갖는 상태로 현재 word 등록
- 기록된 Map 객체 조회
2-1. 단 하나의 word를 갖는 문자 간격 탐색하여 반환
function oddString(words: string[]): string {
const map = new Map<string, string[]>()
for(const word of words) {
const diff = []
for(let i = 1; i < word.length; i++) {
const prev = word[i - 1].charCodeAt(0)
const cur = word[i].charCodeAt(0)
diff.push(cur - prev)
}
const key = JSON.stringify(diff)
map.set(key, [...(map.get(key) ?? []), word])
}
for(const [key, value] of map) {
if(value.length === 1) {
return value[0]
}
}
return ""
};