标签:val col lag ini pytho dict elf root object
def calculate_sum(): s = 0 i = 1 flag = 1 while not (1/i < 1e-4): s += flag*1/i i += 1 flag = -flag return s print("%.6f" % calculate_sum())
trie = Trie() trie.insert("A") trie.insert("to") trie.insert("ten") trie.insert("i") trie.insert("in") trie.insert("inn") trie.search("in") # True trie.search("ink") # False import collections class Node(object): def __init__(self, val=""): self.val = val self.children = collections.defaultdict(Node) class Trie(object): def __init__(self): self.root = Node("") def insert(self, word): node = self.root for char in word: node = node.children[char] node.val = word def search(self, word): node = self.root for char in word: if char in node.children: node = node.children[char] else: return False return len(node.val) > 0
标签:val col lag ini pytho dict elf root object
原文地址:https://www.cnblogs.com/bonelee/p/10827858.html