From 0be935a8aad76bff8093ad29af06d0d24bab2e57 Mon Sep 17 00:00:00 2001 From: Hao Chen Date: Tue, 20 Apr 2021 18:23:22 +0800 Subject: [PATCH] New Problem Solution - "1832. Check if the Sentence Is Pangram" --- README.md | 1 + .../CheckIfTheSentenceIsPangram.cpp | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 algorithms/cpp/checkIfTheSentenceIsPangram/CheckIfTheSentenceIsPangram.cpp diff --git a/README.md b/README.md index 85ca755d2..63ee03282 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ LeetCode | # | Title | Solution | Difficulty | |---| ----- | -------- | ---------- | +|1832|[Check if the Sentence Is Pangram](https://leetcode.com/problems/check-if-the-sentence-is-pangram/) | [C++](./algorithms/cpp/checkIfTheSentenceIsPangram/CheckIfTheSentenceIsPangram.cpp)|Easy| |1829|[Maximum XOR for Each Query](https://leetcode.com/problems/maximum-xor-for-each-query/) | [C++](./algorithms/cpp/maximumXorForEachQuery/MaximumXorForEachQuery.cpp)|Medium| |1828|[Queries on Number of Points Inside a Circle](https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/) | [C++](./algorithms/cpp/queriesOnNumberOfPointsInsideACircle/QueriesOnNumberOfPointsInsideACircle.cpp)|Medium| |1827|[Minimum Operations to Make the Array Increasing](https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/) | [C++](./algorithms/cpp/minimumOperationsToMakeTheArrayIncreasing/MinimumOperationsToMakeTheArrayIncreasing.cpp)|Easy| diff --git a/algorithms/cpp/checkIfTheSentenceIsPangram/CheckIfTheSentenceIsPangram.cpp b/algorithms/cpp/checkIfTheSentenceIsPangram/CheckIfTheSentenceIsPangram.cpp new file mode 100644 index 000000000..f76eaa156 --- /dev/null +++ b/algorithms/cpp/checkIfTheSentenceIsPangram/CheckIfTheSentenceIsPangram.cpp @@ -0,0 +1,41 @@ +// Source : https://leetcode.com/problems/check-if-the-sentence-is-pangram/ +// Author : Hao Chen +// Date : 2021-04-20 + +/***************************************************************************************************** + * + * A 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. + * + * Example 1: + * + * Input: sentence = "thequickbrownfoxjumpsoverthelazydog" + * Output: true + * Explanation: sentence contains at least one of every letter of the English alphabet. + * + * Example 2: + * + * Input: sentence = "leetcode" + * Output: false + * + * Constraints: + * + * 1 <= sentence.length <= 1000 + * sentence consists of lowercase English letters. + ******************************************************************************************************/ + +class Solution { +public: + bool checkIfPangram(string sentence) { + bool stat[26] = {false}; + for(auto& c: sentence) { + stat[c - 'a'] = true; + } + for(auto& s : stat) { + if (!s) return false; + } + return true; + } +};