1832. Check if the Sentence Is Pangram

양성준·2025년 4월 13일

코딩테스트

목록 보기
17/102

문제

https://leetcode.com/problems/check-if-the-sentence-is-pangram/description/

풀이

class Solution {
    public boolean checkIfPangram(String sentence) {
        Set<Character> set = new HashSet<>();
        
        for(char c : sentence.toCharArray()) {
            set.add(c);
        }

        return set.size() == 26;
    }
}
  • senetence가 소문자 알파벳이 최소 하나씩 들어있는 문장인지 확인하는 문제
  • 중복을 무시하고, 알파벳이 최소 한번씩만 존재하는지 확인하면 된다.
    • map을 사용해도 좋지만, 알파벳이 몇 번 등장하는지는 중요하지 않기 때문에
    • set을 사용하여 Key값만 저장하고, size가 26이라면 전부 등장한 것이므로 true,
      아니라면 false를 반환한다.
      • 정렬도, 저장순서 유지도 필요 없으므로 HashSet 사용
profile
백엔드 개발자

0개의 댓글