# Implement Trie (Prefix Tree) (Leetcode 208)

Problem Link: <https://leetcode.com/problems/implement-trie-prefix-tree/description/>

```python
class Node:
    def __init__(self):
        self.children = {}
        self.isEndOfWord = False


class Trie:
    def __init__(self):
        self.root = Node()
        
    def insert(self, word: str) -> None:
        curr = self.root
        for char in word:
            if(char not in curr.children):
                curr.children[char]=Node()
            curr=curr.children[char]
        curr.isEndOfWord=True
        

    def search(self, word: str) -> bool:
        curr = self.root
        for char in word:
            if(char not in curr.children):
                return False
            curr=curr.children[char]
        if(curr.isEndOfWord==True):
            return True
        else:
            return False
        

    def startsWith(self, prefix: str) -> bool:
        curr = self.root
        for char in prefix:
            if(char not in curr.children):
                return False
            curr=curr.children[char]
        return True
```
