Skip to content

Instantly share code, notes, and snippets.

@Jarvvski
Last active August 10, 2018 14:17
Show Gist options
  • Select an option

  • Save Jarvvski/5b694cd8771f4db290716d522c8ef267 to your computer and use it in GitHub Desktop.

Select an option

Save Jarvvski/5b694cd8771f4db290716d522c8ef267 to your computer and use it in GitHub Desktop.
import java.util.*;
public class PangramChecker {
private final int MAX_NUM_UNIQUE_VALUES = 26;
public boolean isPangram(String input) {
if (input == "") {
return false;
}
// remove all whitespace
String workingInput = input.replaceAll("\\s+","");
if (workingInput.length() < MAX_NUM_UNIQUE_VALUES) {
// we don't have enough values to cover the alphabet
// so escape early
return false;
}
// setup
char[] characters = workingInput.toCharArray();
HashMap<Character, Boolean> map = new HashMap<Character, Boolean>();
// iterate over input set
for (Character character : characters) {
// if it's not even a character, escape this iteration
if (!Character.isLetter(character)) {
continue;
}
// lower it
character = Character.toLowerCase(character);
// if its not in the map already, add it in
if (map.get(character) == null) {
map.put(character, true);
}
}
if (map.size() < MAX_NUM_UNIQUE_VALUES) {
// haven't gotten enough unique values for the set
return false;
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment