This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"io/ioutil" | |
"math" | |
"strconv" | |
"strings" | |
"sync" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node(object): | |
def __init__(s): | |
s.edges = {} | |
s.term = False | |
def insert(s, w): | |
s.term = not w or s.edges.setdefault(w[0], Node()).insert(w[1:]) or s.term | |
def exists(s, w): | |
return s.term if not w else w[0] in s.edges and s.edges[w[0]].exists(w[1:]) |