Ad

An isogram a word where no letter repeats itself more than once, no matter what case it is.
Write a function that checks whether a word is an isogram or not.

Code
Diff
  • using System.Linq;
    
    public class Kata
    {
      public static bool IsIsogram(string str) => str.Length == str.ToLower().Distinct().Count();
    }
    • using System;
    • using System.Linq;
    • using System.Linq;
    • public class Kata
    • {
    • public static bool IsIsogram(string str)
    • {
    • string seen = "";
    • foreach(var c in str.ToLower()) {
    • if(seen.Contains(c)) return false;
    • seen = seen + c;
    • }
    • return true;
    • }
    • public static bool IsIsogram(string str) => str.Length == str.ToLower().Distinct().Count();
    • }
Code
Diff
  • using System;
    using System.Linq; 
    
    public class Kata
    {
      public static bool IsIsogram(string str) 
      {
        string seen = "";
        
        foreach(var c in str.ToLower()) {
          if(seen.Contains(c)) return false;
          seen = seen + c;
        }
        
        return true;
      }
    }
    • /*
    • using System;
    • using System.Linq;
    • */
    • using System.Linq;
    • public class Kata
    • {
    • public static bool IsIsogram(string str)
    • {
    • System.Collections.Generic.HashSet<int> seen = new System.Collections.Generic.HashSet<int>();
    • foreach (char c in str)
    • {
    • int c_insensitive = (int) c & 0x1f;
    • if (seen.Contains(c_insensitive))
    • {
    • return false;
    • }
    • seen.Add(c_insensitive);
    • string seen = "";
    • foreach(var c in str.ToLower()) {
    • if(seen.Contains(c)) return false;
    • seen = seen + c;
    • }
    • return true;
    • }
    • }