using System.Linq;
public static class Isogram
{
public static bool IsIsogram(string word)
{
var lowerLetters = word.ToLower().Where(char.IsLetter).ToList();
return lowerLetters.Distinct().Count() == lowerLetters.Count;
}
}
The steps for this solution are
-
ToLower
produces a newstring
with its characters changed to lower case. That string is chained toWhere
. -
Where
uses IsLetter to filter thestring
so only Unicode letters get put into a List. So no hyphens nor apostrophes (nor anything else that is not a letter) will make it into theList
. -
Distinct
usesCount
to get the number of unique letters in thelowerLetters
List
. - The function returns whether the number of distinct letters is the same as the number of all letters.
A string is an isogram if its number of distinct letters is the same as the number of all its letters.
- The word
Bravo
is an isogram because it has five distinct letters and five letters total. - The word
Alpha
is not an isogram becausea
is considered to repeatA
, so it has only four distinct letters but five letters total.
20th Nov 2024
·
Found it useful?