Skip to content

Commit 50ca650

Browse files
committed
Added Largest Substring Between Two Equal Characters.java
1 parent daf09ec commit 50ca650

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public int maxLengthBetweenEqualCharacters(String s) {
3+
Map<Character, Integer> startIndex = new HashMap<>();
4+
int largestSubstringLength = -1;
5+
for (int i = 0; i < s.length(); i++) {
6+
char c = s.charAt(i);
7+
startIndex.putIfAbsent(c, i);
8+
largestSubstringLength = Math.max(largestSubstringLength, i - startIndex.get(c) - 1);
9+
}
10+
return largestSubstringLength;
11+
}
12+
}

0 commit comments

Comments
 (0)