diff --git a/0208-implement-trie-prefix-tree/0208-implement-trie-prefix-tree.cpp b/0208-implement-trie-prefix-tree/0208-implement-trie-prefix-tree.cpp new file mode 100644 index 0000000..fa184e1 --- /dev/null +++ b/0208-implement-trie-prefix-tree/0208-implement-trie-prefix-tree.cpp @@ -0,0 +1,28 @@ +class Trie { +public: + +unordered_mapmpp,mp; + Trie() { + + } + + void insert(string word) { + mpp[word]++; + string s; + for(auto it : word) + { + s.push_back(it); + if(mp[s]==0) mp[s]++; + } + } + + bool search(string word) { + if(mpp[word]) return true; + return false; + } + + bool startsWith(string prefix) { + if(mp[prefix]) return true; + return false; + } +};