deno.land / x / masx200_leetcode_test@10.6.5 / largest-substring-between-two-equal-characters / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
export default function maxLengthBetweenEqualCharacters(s: string): number { const firstIndex: number[] = new Array(26).fill(-1); let maxLength = -1; for (let i = 0; i < s.length; i++) { const key = s[i].charCodeAt(0) - "a".charCodeAt(0); if (firstIndex[key] < 0) { firstIndex[key] = i; } else { maxLength = Math.max(maxLength, i - firstIndex[key] - 1); } } return maxLength;}
masx200_leetcode_test
leetcode题解和一些测试工具
DocumentationDocumentation
GitHub Repositorymasx200/leetcode-test
GitHub Stars
4

Version Info

Tagged at
4 months ago