[LeetCode] 3120. Count the Number of Special Characters I

Chobby·2025년 12월 22일

LeetCode

목록 보기
858/895

😎풀이

  1. word의 Set 변환 -> 중복 제거 및 탐색 시간복잡도 감소
  2. set 순회
    2-1. 소문자만 탐색하며, 동일 문자의 대문자형이 있는 경우 카운트
  3. 특정 알파벳의 대소문자를 모두 포함하는 알파벳의 수 반환
function numberOfSpecialChars(word: string): number {
    const set = new Set(word)
    let specialChars = 0
    for(const char of set) {
        const curUpper = char.toUpperCase()
        if(char === curUpper) continue
        if(set.has(curUpper)) specialChars++
    }
    return specialChars
};
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글