[LeetCode] 1832. Check if the Sentence Is Pangram

Chobby·4일 전
1

LeetCode

목록 보기
613/650

😎풀이

  1. sentence 글자별로 분리
  2. 문자열 코드로 변환
  3. 오름차 순 정렬
  4. 소문자 a의 코드인 97부터 탐색
  5. 최종적으로 z까지 찾았다면 true 아니라면, false 반환
function checkIfPangram(sentence: string): boolean {
    const splitted = [...sentence]
    const transToCode = splitted.map(char => char.charCodeAt(0))
    const sorted = transToCode.toSorted((a, b) => a - b)
    let curCode = 97
    for(const num of sorted) {
        if(num > curCode) return false
        else if(num === curCode) curCode++
    }
    return curCode > 122
};
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글