题目演变:
顺着这个思路, 想到了递归。
上面这种思路也是可以的, 但是最终用判断字符中各字母出现的数字来实现。
/** 18.12.08 *//*** @param {string} s1* @param {string} s2* @return {boolean}*/var checkInclusion = function (s1, s2) {const s1Obj = {}const s1Length = s1.lengthfor (let i = 0; i < s1Length; i++) {if (s1Obj[s1[i]]) {s1Obj[s1[i]] = ++s1Obj[s1[i]]} else {s1Obj[s1[i]] = 1}}const s2Length = s2.lengthif (s1Length > s2Length) {return false}const count = s2Length - s1Lengthlet str = ''for (let i = 0; i <= count; i++) {str = s2.slice(i, s1Length + i)const s2Obj = {}for (let z = 0; z < str.length; z++) {if (!s1Obj[str[z]]) {i = i + zbreak}if (s2Obj[str[z]]) {s2Obj[str[z]] = s2Obj[str[z]] + 1} else {s2Obj[str[z]] = 1}}let bool = truefor (let y = 0; y < Object.keys(s1Obj).length; y++) {if (s2Obj[Object.keys(s1Obj)[y]] !== s1Obj[Object.keys(s1Obj)[y]]) {bool = falsebreak}}if (bool === true) {return true}}return false};