Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | export function maxLengthSubString(str: string): number { const endIndex = str.length - 1; let res = 1; let L = 0; let R = 1; let subStr = str[L]; if (!str) return 0; if (str.length < 2) return 1; while (L <= endIndex && R <= endIndex) { if (!subStr.includes(str[R])) { subStr = subStr + str[R]; res = Math.max(subStr.length, res); R++; } else { L++; subStr = str[L]; R = L + 1; } } return res; } console.log(maxLengthSubString("a"), "expect: " + 1); console.log(maxLengthSubString(""), "expect: " + 0); console.log(maxLengthSubString("abcabcbb"), "expect: " + 3); console.log(maxLengthSubString("ab"), "expect: " + 2); console.log(maxLengthSubString("aaaaaa"), "expect: " + 1); console.log(maxLengthSubString("aabcDfffaaaa"), "expect: " + 5); |