-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution208.hpp
More file actions
41 lines (33 loc) · 838 Bytes
/
Solution208.hpp
File metadata and controls
41 lines (33 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//
// Solution208.hpp
// Algorithm
//
// Created by Pancf on 2020/12/19.
//
#ifndef Solution208_hpp
#define Solution208_hpp
#include <stdio.h>
#include <string>
class Trie {
public:
/** Initialize your data structure here. */
Trie() {
root = new TrieNode;
}
/** Inserts a word into the trie. */
void insert(std::string word);
/** Returns if the word is in the trie. */
bool search(std::string word);
/** Returns if there is any word in the trie that starts with the given prefix. */
bool startsWith(std::string prefix);
private:
struct TrieNode {
bool isEnd;
TrieNode *links[26];
TrieNode(): isEnd(false) {
for (int i = 0; i < 26; ++i) links[i] = nullptr;
}
};
TrieNode *root;
};
#endif /* Solution208_hpp */