Skip to content

Commit 2b070fe

Browse files
authored
Create 1624-largest-substring-between-two-equal-characters.js
1 parent c1c7f53 commit 2b070fe

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @param {string} s
3+
* @return {number}
4+
*/
5+
const maxLengthBetweenEqualCharacters = function(s) {
6+
const m = {}
7+
if(s ==null || s.length <= 1) return -1
8+
let res = -1
9+
for(let i = 0, len = s.length; i< len;i++) {
10+
if(m[s[i]] != null) {
11+
res = Math.max(res, i - m[s[i]] - 1)
12+
} else {
13+
m[s[i]] = i
14+
}
15+
16+
}
17+
return res
18+
};

0 commit comments

Comments
 (0)