Skip to content

Commit 6465c2b

Browse files
committed
Solved 1624 - Largest Substring Between Two Equal Characters
1 parent 561d7ae commit 6465c2b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function maxLengthBetweenEqualCharacters(s: string): number {
2+
const charPosMap = new Map<string, number>();
3+
let ans = -1;
4+
5+
for (let i = 0; i < s.length; i++)
6+
if (!charPosMap.has(s[i]))
7+
charPosMap.set(s[i], i);
8+
else
9+
ans = Math.max(ans, i - charPosMap.get(s[i]) - 1);
10+
11+
return ans;
12+
};

0 commit comments

Comments
 (0)