-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImplementTrie.cpp
More file actions
executable file
·56 lines (44 loc) · 949 Bytes
/
ImplementTrie.cpp
File metadata and controls
executable file
·56 lines (44 loc) · 949 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// ImplementTrie.cpp
// leetcode
//
// Created by witwolf on 5/8/15.
// Copyright (c) 2015 witwolf. All rights reserved.
//
#include <iostream>
#include <string>
using namespace std;
class TrieNode {
public:
// Initialize your data structure here.
TrieNode() {
}
private:
TrieNode* nexts[26];
bool end;
char val;
};
class Trie {
public:
Trie() {
root = new TrieNode();
}
// Inserts a word into the trie.
void insert(string s) {
}
// Returns if the word is in the trie.
bool search(string key) {
return false;
}
// Returns if there is any word in the trie
// that starts with the given prefix.
bool startsWith(string prefix) {
return false;
}
private:
TrieNode* root;
};
// Your Trie object will be instantiated and called as such:
// Trie trie;
// trie.insert("somestring");
// trie.search("key");