개발 일지
1832. Check if the Sentence Is Pangram (문장이 Pangram인지 확인하기) C# 본문
코딩 테스트/LeetCode
1832. Check if the Sentence Is Pangram (문장이 Pangram인지 확인하기) C#
포카리tea 2022. 10. 17. 14:33A pangram is a sentence where every letter of the English alphabet appears at least once.
Given a string sentence containing only lowercase English letters, return true if sentence is a pangram, or false otherwise.
pangram이란 영어 알파벳의 모든 글자가 적어도 한 번씩은 나타나는 문장입니다.
소문자만 포함한 문자열 sentence가 주어집니다. sentence가 pangram이면 true를 그렇지 않으면 false를 반환하십시오.
예시 1:
입력: sentence = "thequickbrownfoxjumpsoverthelazydog"
출력: true
설명: sentence는 모든 알파벳의 모든 글자를 적어도 하나씩을 포함합니다.
예시 2:
입력: sentence = "leetcode"
출력: false
조건:
- 1 <= sentence.length <= 1000
- sentence는 소문자로만 구성되어있습니다.
정답:
public class Solution {
public bool CheckIfPangram(string sentence) {
char[] charArray = sentence.ToCharArray();
if (charArray.Distinct().ToArray().Length == 26)
return true;
else
return false;
}
}
해설: 모든 알파벳이 들어간다면 중복제거를 했을때 길이가 26이 나와야합니다
'코딩 테스트 > LeetCode' 카테고리의 다른 글
219. Contains Duplicate II (중복 포함 II) C# (0) | 2022.10.31 |
---|---|
1239. Maximum Length of a Concatenated String with Unique Characters (고유한 문자로 연결된 문자열의 최대 길이) C# (0) | 2022.10.25 |
38. Count and Say (세고 말하기) C# (0) | 2022.10.19 |
258. Add Digits (자릿수 더하기) C# (0) | 2022.10.11 |
231. Power of Two (2의 거듭제곱) C# (0) | 2022.10.06 |