[LeetCode] Check if the Sentence Is Pangram

아르당·2026년 7월 7일

LeetCode

목록 보기
393/579
post-thumbnail

문제를 이해하고 있다면 바로 풀이를 보면 됨
전체 코드로 바로 넘어가도 됨
마음대로 번역해서 오역이 있을 수 있음

Problem

팬그램은 영어 알파벳의 모든 글자가 적어도 한번씩 등장하는 문장이다.

오직 영어 소문자로 구성된 문자열 sentence가 주어졌을 때, sentence가 팬그램이면 true, 그렇지 않으면 false를 반환해라.

Example

#1
Input: sentence = "thequickbrownfoxjumpsoverthelazydog"
Output: true
Explanation: sentence는 영어 알파벳의 모든 문자를 하나씩 포함한다.

#2
Input: sentence = "leetcode"
Output: false

Constraints

  • 1 <= sentence.length <= 1000
  • sentence는 영어 소문자로 구성된다.

Solved

class Solution {
    public boolean checkIfPangram(String sentence) {
        if(sentence.length() < 26){
            return false;
        }

        boolean[] alphabet = new boolean[26];

        for(char c : sentence.toCharArray()){
            if(c >= 'a' && c <= 'z'){
                alphabet[c - 'a'] = true;
            }
        }

        for(boolean flag : alphabet){
            if(!flag){
                return false;
            }
        }

        return true;
    }
}
profile
내 마음대로 코드 작성하는 세상

0개의 댓글