pass 208 string medium
This commit is contained in:
parent
364ad7a999
commit
8b067e91be
26
208-240525-pass/main.py
Normal file
26
208-240525-pass/main.py
Normal file
@ -0,0 +1,26 @@
|
||||
class Trie:
|
||||
|
||||
def __init__(self):
|
||||
self.l = []
|
||||
|
||||
def insert(self, word: str) -> None:
|
||||
self.l.append(word)
|
||||
|
||||
def search(self, word: str) -> bool:
|
||||
for s in self.l:
|
||||
if s == word:
|
||||
return True
|
||||
return False
|
||||
|
||||
def startsWith(self, prefix: str) -> bool:
|
||||
for s in self.l:
|
||||
if s.startswith(prefix):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
# Your Trie object will be instantiated and called as such:
|
||||
# obj = Trie()
|
||||
# obj.insert(word)
|
||||
# param_2 = obj.search(word)
|
||||
# param_3 = obj.startsWith(prefix)
|
Loading…
Reference in New Issue
Block a user