Leetcode211 添加与搜索单词
var WordDictionary = function() {
this.words=[]
};
/**
* @param {string} word
* @return {void}
*/
WordDictionary.prototype.addWord = function(word) {
let wordLen=word.length
if(this.words[wordLen]==undefined){
this.words[wordLen]=[word]
}else{
this.words[wordLen].push(word)
}
};
/**
* @param {string} word
* @return {boolean}
*/
WordDictionary.prototype.search = function(word) {
let wordLen=word.length
if(this.words[wordLen]==undefined){
return false
}
if(!word.includes('.')){
return this.words[wordLen].includes(word)
}
let reg=new RegExp(word)
return this.words[wordLen].some(i=>reg.test(i))
};
/**
* Your WordDictionary object will be instantiated and called as such:
* var obj = new WordDictionary()
* obj.addWord(word)
* var param_2 = obj.search(word)
*/
不能全部通过

浙公网安备 33010602011771号