| | 1 | | // -------------------------------------------------------------------------------- |
| | 2 | | // Copyright (C) 2025 Eugene Eremeev (also known as Yevhenii Yeriemeieiv). |
| | 3 | | // All Rights Reserved. |
| | 4 | | // -------------------------------------------------------------------------------- |
| | 5 | | // This software is the confidential and proprietary information of Eugene Eremeev |
| | 6 | | // (also known as Yevhenii Yeriemeieiv) ("Confidential Information"). You shall not |
| | 7 | | // disclose such Confidential Information and shall use it only in accordance with |
| | 8 | | // the terms of the license agreement you entered into with Eugene Eremeev (also |
| | 9 | | // known as Yevhenii Yeriemeieiv). |
| | 10 | | // -------------------------------------------------------------------------------- |
| | 11 | |
|
| | 12 | | namespace LeetCode.Algorithms.CheckIfTheSentenceIsPangram; |
| | 13 | |
|
| | 14 | | /// <inheritdoc /> |
| | 15 | | public class CheckIfTheSentenceIsPangramHashSet : ICheckIfTheSentenceIsPangram |
| | 16 | | { |
| 4 | 17 | | private readonly HashSet<char> _alphabetHashSet = |
| 4 | 18 | | [ |
| 4 | 19 | | 'a', |
| 4 | 20 | | 'b', |
| 4 | 21 | | 'c', |
| 4 | 22 | | 'd', |
| 4 | 23 | | 'e', |
| 4 | 24 | | 'f', |
| 4 | 25 | | 'g', |
| 4 | 26 | | 'h', |
| 4 | 27 | | 'i', |
| 4 | 28 | | 'j', |
| 4 | 29 | | 'k', |
| 4 | 30 | | 'l', |
| 4 | 31 | | 'm', |
| 4 | 32 | | 'n', |
| 4 | 33 | | 'o', |
| 4 | 34 | | 'p', |
| 4 | 35 | | 'q', |
| 4 | 36 | | 'r', |
| 4 | 37 | | 's', |
| 4 | 38 | | 't', |
| 4 | 39 | | 'u', |
| 4 | 40 | | 'v', |
| 4 | 41 | | 'w', |
| 4 | 42 | | 'x', |
| 4 | 43 | | 'y', |
| 4 | 44 | | 'z' |
| 4 | 45 | | ]; |
| | 46 | |
|
| | 47 | | /// <summary> |
| | 48 | | /// Time complexity - O(n) |
| | 49 | | /// Space complexity - O(n) |
| | 50 | | /// </summary> |
| | 51 | | /// <param name="sentence"></param> |
| | 52 | | /// <returns></returns> |
| | 53 | | public bool CheckIfPangram(string sentence) |
| 4 | 54 | | { |
| 4 | 55 | | if (sentence.Length < 26) |
| 1 | 56 | | { |
| 1 | 57 | | return false; |
| | 58 | | } |
| | 59 | |
|
| 3 | 60 | | var sentenceHashSet = new HashSet<char>(sentence); |
| | 61 | |
|
| 3 | 62 | | return _alphabetHashSet.All(sentenceHashSet.Contains); |
| 4 | 63 | | } |
| | 64 | | } |