Given such data structure, implement add() and search() method, which support wildcard matching.
? Matches any single character.
* Matches any sequence of characters (including the empty sequence).
class Node
{
Node getChildForLetter(char letter)
Node[] getAllChildren();
boolean isTerminal();
}
//some example:
add("car")
add("caw")
add("cauw")
search(“c*w”)
//should return “caw” and “cauw”.
// "*" could be at any place in the input string.This problem is pretty similar to 211. Add and Search Word - Data structure design, but you need to also implement wildcard searching. The brute-force way is not hard to find out, but what about the optimization, any thought on this?
Comments (6)

