-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d43c5b6
commit 6fff585
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
CodeWarsChallenges/CodeWarsChallenges/Strings/6kyu/Detect Pangram/DetectPangram.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
namespace CodeWarsChallenges.Strings._6kyu.Detect_Pangram; | ||
|
||
public static class DetectPangram | ||
{ | ||
private static readonly HashSet<int> ASCIIAlphabet = new() | ||
{ | ||
65, | ||
66, | ||
67, | ||
68, | ||
69, | ||
70, | ||
71, | ||
72, | ||
73, | ||
74, | ||
75, | ||
76, | ||
77, | ||
78, | ||
79, | ||
80, | ||
81, | ||
82, | ||
83, | ||
84, | ||
85, | ||
86, | ||
87, | ||
88, | ||
89, | ||
90 | ||
}; | ||
|
||
|
||
public static bool IsPangram(string str) | ||
{ | ||
var countAlphabet = ASCIIAlphabet.Count; | ||
var hashSet = new HashSet<int>(); | ||
var stringUpper = str.ToUpper(); | ||
var count = 0; | ||
|
||
for (var i = 0; i < stringUpper.Length; i++) | ||
{ | ||
if (count == countAlphabet) | ||
return true; | ||
|
||
if (!ASCIIAlphabet.Contains((int)stringUpper[i])) | ||
continue; | ||
|
||
if (hashSet.Contains((int) stringUpper[i])) | ||
continue; | ||
|
||
hashSet.Add(stringUpper[i]); | ||
count++; | ||
} | ||
|
||
return count == countAlphabet; | ||
} | ||
} |