ryuk33
BAN USERstd::unordered_set<std::string> dictionary;
void PopulateDictionary(const std::vector<std::string> &words) {
for (size_t i = 0; i < words.size(); ++i) {
PopulateWord(words[i], 0, '');
}
}
void PopulateWord(const std::string &word, int position, const std::string &str) {
if(position == word.size() - 1) {
dictionary.insert(str);
return;
}
PopulateWord(word, position + 1, str + '*');
PopulateWord(word, position + 1, str + word[position]);
}
std::string Search(const std::string &word) {
if (dictionary.find(word) == dictionary.end()) {
return 'NO';
} else {
return 'YES';
}
}
struct Node {
Node *next;
char content;
};
Node* Reverse(Node *head) {
Node *prev = NULL;
Node *node = head;
Node *next = head->next;
while (node->next != NULL) {
node->next = prev;
prev = node;
node = next;
next = node->next;
}
node->next = prev;
return node;
}
Sorry, made a mistake.
New code as below:
- ryuk33 February 25, 2015