leetcode/208-240525-pass/main.py
2024-05-25 16:38:18 +02:00

26 lines
612 B
Python

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)