Detect Pangram

Detect Pangram

Description:

A pangram is a sentence that contains every single letter of the alphabet at least once. For example, the sentence “The quick brown fox jumps over the lazy dog” is a pangram, because it uses the letters A-Z at least once (case is irrelevant).

Given a string, detect whether or not it is a pangram. Return True if it is, False if not. Ignore numbers and punctuation.


public class PangramChecker {
  public boolean check(String sentence){
        if (sentence == null) {
	        return false;
	    }
	    String strUpper = sentence.toUpperCase();

	    Stream<Character> filteredCharStream = strUpper.chars()
	      .filter(item -> ((item >= 'A' && item <= 'Z')))
	      .mapToObj(c -> (char) c);

	    Map<Character, Boolean> alphabetMap = 
	      filteredCharStream.collect(Collectors.toMap(item -> item, k -> Boolean.TRUE, (p1, p2) -> p1));

	    return alphabetMap.size() == 26;
  }
}
public class PangramChecker {
  public boolean check(String sentence){
        for (char c = 'a'; c<='z'; c++)
            if (!sentence.toLowerCase().contains("" + c))
                return false;
        return true;

  }
}
public class PangramChecker {
  public boolean check(String sentence){
    return sentence.chars().map(Character::toLowerCase).filter(Character::isAlphabetic).distinct().count() == 26;
  }
}
public class PangramChecker {
  public boolean check(String sentence){
        String x = sentence.toLowerCase();
        if(x.contains("a") && x.contains("b") && x.contains("c") && x.contains("d")
                && x.contains("e") && x.contains("f") && x.contains("g")
                && x.contains("h") && x.contains("i") && x.contains("j")
                && x.contains("k") && x.contains("l") && x.contains("m")
                && x.contains("n") && x.contains("o") && x.contains("p")
                && x.contains("q") && x.contains("r") && x.contains("s")
                && x.contains("t") && x.contains("u") && x.contains("v")
                && x.contains("w") && x.contains("x") && x.contains("y")
                && x.contains("z")){
            return true;
        }else{
            return false;
        }
    }
}class PangramChecker {
    boolean check(final String sentence) {
        return sentence.chars()
            .filter(Character::isLetter)
            .map(Character::toLowerCase)
            .distinct()
            .count() == 26;
    }
}
public class PangramChecker {
  public boolean check(String sentence){
    long result = sentence.toLowerCase().chars().filter(i -> i >= 'a' && i <= 'z').distinct().count();
    return result == 26;
  }
}

دیدگاهتان را بنویسید