Skip to content

Commit b545b53

Browse files
authored
Create largest-substring-between-two-equal-characters.py
1 parent 6443f9f commit b545b53

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def maxLengthBetweenEqualCharacters(self, s):
6+
"""
7+
:type s: str
8+
:rtype: int
9+
"""
10+
result, lookup = -1, {}
11+
for i, c in enumerate(s):
12+
result = max(result, i-lookup.setdefault(c, i)-1)
13+
return result

0 commit comments

Comments
 (0)