/**
* @param {string} s
* @param {string[]} words
* @return {number[]}
*/
var findSubstring = function (s, words) {
const k = words[0].length; // 字符串长度
let PointArray, Shed; // 存储占用情况
const len = s.length;
const result = [];
let left, right;
for (let t = 0; t < k; t++) {
PointArray = [...words]; // 存储占用情况
Shed = [];
left = t; // 当下左下标
right = t;
for (; right < len;) {
const str = s.slice(right, right + k);
// 不存在该字符串
if (!words.includes(str)) {
left = right + k;;
PointArray = [...words];
Shed = [];
} else {
const index = PointArray.findIndex(item => item === str);
// 已无可用
if (index === -1) {
// 从已匹配字符串查找
const index2 = Shed.findIndex(item => item === str);
const arr = Shed.splice(0, index2);
PointArray = PointArray.concat(arr);
const top = Shed.shift();
Shed.push(top);
left = left + k * (index2 + 1);
} else {
Shed.push(PointArray.splice(index, 1)[0]);
// 如果字符串长度相等 匹配加1
if (PointArray.length === 0) {
result.push(left);
left = left + k;
PointArray.push(Shed.shift());
}
}
}
right = right + k;
}
}
return result;
};