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

Version Info

Tagged at
2 years ago