public class WordGamesUtil extends Object
Modifier and Type | Field and Description |
---|---|
static Dictionary |
DICTIONARY
A dictionary of lower case English words.
|
Modifier and Type | Method and Description |
---|---|
static SortedSet<String> |
allAdjacentTo(String s)
Returns a sorted set of all words in
WordGamesUtil.DICTIONARY that are adjacent to the string
s.
|
static SortedSet<String> |
allAdjacentTo(String s,
int index)
Returns a sorted set of all words in
WordGamesUtil.DICTIONARY that are adjacent to the string
s and differ from s exactly at the given index.
|
static boolean |
areAdjacent(String s,
String t)
Determines if two strings are adjacent words.
|
static int |
distance(String s,
String t)
Returns the Hamming distance between two strings.
|
public static final Dictionary DICTIONARY
public static int distance(String s, String t)
IllegalArgumentException
- if s.length() != t.length()s
- a stringt
- a stringpublic static boolean areAdjacent(String s, String t)
s
- a stringt
- a stringpublic static SortedSet<String> allAdjacentTo(String s)
s
- a stringpublic static SortedSet<String> allAdjacentTo(String s, int index)
For example, suppose that we want to find all words that can be formed by changing the 't' in "cat". alldjacentTo("cat", 2) returns the set containing the strings "cab", "cad", "cam", "can", "cap", "car", "caw", "cay".
s
- a stringindex
- the index where the adjacent words differ from s