文章 评论 浏览 27
const find = (S, T) => { const indexList = []; if(S.length < T.length) return -1; for(let i = 0; i <= S.length - T.length; i++) { if(S.slice(i, i + T.length) === T) indexList.push(i) } return indexList.length? indexList : -1;}
文章 0 评论 0
接受
const find = (S, T) => {
const indexList = [];
if(S.length < T.length) return -1;
for(let i = 0; i <= S.length - T.length; i++) {
if(S.slice(i, i + T.length) === T) indexList.push(i)
}
return indexList.length? indexList : -1;
}
第 71 题: 实现一个字符串匹配算法,从长度为 n 的字符串 S 中,查找是否存在字符串 T,T 的长度是 m,若存在返回所在位置