201 Bitwise AND of Numbers Range
题意:闭区间所有数值求AND
思路:分治递归
207 Course Schedule
题意:先修课依赖
思路:BFS
208 Implement Trie (Prefix Tree)
题意:前缀树
struct Node{
Node* dic[26];
bool isWord;
Node(){
for(int i = 0;i < 26;++ i){
dic[i] = NULL;
}
isWord = false;
}
};
class Trie {
public:
Node* root;
Trie() {
root = new Node();
}
/** Inserts a word into the trie. */
void insert(string word) {
Node* i = root;
for(auto a : word){
int c = a - 'a';
if(i->dic[c] == NULL){
i->dic[c] = new Node();
}
i = i->dic[c];
}
i->isWord = true;
}
/** Returns if the word is in the trie. */
bool search(string word) {
Node* i = root;
for(auto a : word){
int c = a - 'a';
if(i->dic[c] == NULL){
return false;
}
i = i->dic[c];
}
return i->isWord;
}
/** Returns if there is any word in the trie that starts with the given prefix. */
bool startsWith(string prefix) {
Node* i = root;
for(auto a : prefix){
int c = a - 'a';
if(i->dic[c] == NULL){
return false;
}
i = i->dic[c];
}
return true;
}
};
/**
* Your Trie object will be instantiated and called as such:
* Trie obj = new Trie();
* obj.insert(word);
* bool param_2 = obj.search(word);
* bool param_3 = obj.startsWith(prefix);
*/
209 Minimum Size Subarray Sum
题意:不小于某数字的最短子数列
思路:DP