Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a12e2e0

Browse files
committedApr 23, 2025
Add solution #1624
1 parent 92e7d1f commit a12e2e0

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed
 

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,428 LeetCode solutions in JavaScript
1+
# 1,429 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1252,6 +1252,7 @@
12521252
1620|[Coordinate With Maximum Network Quality](./solutions/1620-coordinate-with-maximum-network-quality.js)|Medium|
12531253
1621|[Number of Sets of K Non-Overlapping Line Segments](./solutions/1621-number-of-sets-of-k-non-overlapping-line-segments.js)|Medium|
12541254
1622|[Fancy Sequence](./solutions/1622-fancy-sequence.js)|Hard|
1255+
1624|[Largest Substring Between Two Equal Characters](./solutions/1624-largest-substring-between-two-equal-characters.js)|Easy|
12551256
1657|[Determine if Two Strings Are Close](./solutions/1657-determine-if-two-strings-are-close.js)|Medium|
12561257
1668|[Maximum Repeating Substring](./solutions/1668-maximum-repeating-substring.js)|Easy|
12571258
1669|[Merge In Between Linked Lists](./solutions/1669-merge-in-between-linked-lists.js)|Medium|
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* 1624. Largest Substring Between Two Equal Characters
3+
* https://leetcode.com/problems/largest-substring-between-two-equal-characters/
4+
* Difficulty: Easy
5+
*
6+
* Given a string s, return the length of the longest substring between two equal characters,
7+
* excluding the two characters. If there is no such substring return -1.
8+
*
9+
* A substring is a contiguous sequence of characters within a string.
10+
*/
11+
12+
/**
13+
* @param {string} s
14+
* @return {number}
15+
*/
16+
var maxLengthBetweenEqualCharacters = function(s) {
17+
const charFirstIndex = new Map();
18+
let maxLength = -1;
19+
20+
for (let i = 0; i < s.length; i++) {
21+
const char = s[i];
22+
if (charFirstIndex.has(char)) {
23+
maxLength = Math.max(maxLength, i - charFirstIndex.get(char) - 1);
24+
} else {
25+
charFirstIndex.set(char, i);
26+
}
27+
}
28+
29+
return maxLength;
30+
};

0 commit comments

Comments
 (0)
Please sign in to comment.