-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathIsogramChecker.java
More file actions
33 lines (31 loc) · 879 Bytes
/
IsogramChecker.java
File metadata and controls
33 lines (31 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.HashSet;
import java.util.Set;
/**
* Determine if a word or phrase is an isogram.
*
* An isogram (also known as a "nonpattern word") is a word or phrase without a repeating letter,
* however spaces and hyphens are allowed to appear multiple times.
*
* Examples of isograms:
*
* lumberjacks
* background
* downstream
* six-year-old
*
* The word isograms, however, is not an isogram, because the s repeats.
*/
class IsogramChecker {
boolean isIsogram(String phrase) {
Set<Character> chars = new HashSet<Character>();
for (Character character : phrase.toCharArray()) {
if (character == ' ' || character == '-')
continue;
else if (chars.contains(Character.toUpperCase(character)))
return false;
else
chars.add(Character.toUpperCase(character));
}
return true;
}
}