力扣:https://leetcode.cn/problems/longest-substring-without-repeating-characters/
本人题解:
暴力解法
/**
* @param {string} s
* @return {number}
*/
var lengthOfLongestSubstring = function (s) {
if (s.length <= 1) return s.length;
let maxLen = 0;
for (let i = 0; i < s.length; i++) {
const subStrArr = [];
subStrArr.push(s[i])
for (let j = i + 1; j < s.length; j++) {
if (subStrArr.indexOf(s[j]) !== -1) break;
subStrArr.push(s[j]);
}
maxLen = Math.max(subStrArr.length, maxLen);
}
return maxLen;
};